Skip to content

Commit 1f3f60f

Browse files
committed
feat(deps): migrate ESLint and Stylelint configurations to new formats
- Removed old ESLint configuration file and added a new flat config format for ESLint 9+. - Deleted old Stylelint configuration file and created a new one with updated rules. - Added a backup of the autofixable TypeScript file for testing ESLint rules. - Deleted unused CSS file and added a backup with intentional errors for Stylelint testing. - Added a backup TypeScript file with a simple function for ESLint testing. - Created a new Stylelint configuration file with rules to prevent common CSS issues. - Updated TypeScript configuration files to remove deprecated options and adjust output directory.
1 parent a2af2c0 commit 1f3f60f

18 files changed

+5621
-4264
lines changed

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
18
1+
22

jest.config.js renamed to jest.config.cjs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@ module.exports = {
33
preset: 'ts-jest',
44
roots: ['lib'],
55
testEnvironment: 'node',
6-
testPathIgnorePatterns: ['test-project', 'out'],
6+
testPathIgnorePatterns: ['test-project'],
77
testLocationInResults: true,
88
reporters: ['default'],
99
setupFilesAfterEnv: ['jest-extended/all'],
10+
transform: {
11+
'^.+\\.tsx?$': [
12+
'ts-jest',
13+
{
14+
tsconfig: 'tsconfig.spec.json',
15+
},
16+
],
17+
},
18+
transformIgnorePatterns: [
19+
'/node_modules/'
20+
],
1021
};

lib/builder/src/builder.spec.ts

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { toArray, map } from 'rxjs/operators';
33
import { Architect } from '@angular-devkit/architect';
44
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
55
import { logging, schema } from '@angular-devkit/core';
6-
import { exec } from 'child_process';
76
import * as path from 'path';
87

98
describe('Lint', () => {
@@ -12,6 +11,10 @@ describe('Lint', () => {
1211
let logger: logging.Logger;
1312

1413
beforeEach(async () => {
14+
const fs = await import('fs/promises');
15+
await fs.copyFile('test/src/autofixable.ts.bak', 'test/src/autofixable.ts');
16+
await fs.copyFile('test/src/file.ts.bak', 'test/src/file.ts');
17+
await fs.copyFile('test/src/file.css.bak', 'test/src/file.css');
1518
console.log(path.join(process.cwd(), './out'));
1619
const registry = new schema.CoreSchemaRegistry();
1720
registry.addPostTransform(schema.transforms.addUndefinedDefaults);
@@ -30,7 +33,13 @@ describe('Lint', () => {
3033
});
3134

3235
afterEach(async () => {
33-
exec('git restore test/src/');
36+
const fs = await import('fs/promises');
37+
// Remove test files but keep the .bak files
38+
await Promise.all([
39+
fs.rm('test/src/autofixable.ts', { force: true }),
40+
fs.rm('test/src/file.ts', { force: true }),
41+
fs.rm('test/src/file.css', { force: true }),
42+
]);
3443
});
3544

3645
it('has created the correct linting results', async () => {
@@ -64,6 +73,7 @@ describe('Lint', () => {
6473
await run.stop();
6574
logger.complete();
6675

76+
console.log('ACTUAL LOGGER OUTPUT:', JSON.stringify(await loggerPromise, null, 2));
6777
expect(loggerPromise).resolves.toEqual([
6878
{
6979
level: 'info',
@@ -79,21 +89,30 @@ describe('Lint', () => {
7989
},
8090
{
8191
level: 'info',
82-
// @ts-ignore
83-
message: expect.toIncludeMultiple([
84-
//autofixable
85-
'autofixable.ts\n' + " 8:10 error Unnecessary 'else' after 'return' eslint\tno-else-return\n",
86-
//file.css
87-
'file.css\n' +
88-
' 3:3 error Expected indentation of 4 spaces (indentation) stylelint\tindentation\n' +
89-
' 4:3 error Expected indentation of 4 spaces (indentation) stylelint\tindentation\n' +
90-
' 5:3 error Expected indentation of 4 spaces (indentation) stylelint\tindentation\n',
91-
//file.ts
92-
'file.ts\n' + " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n",
93-
// info messages
94-
'✖ 5 problems (5 errors, 0 warnings)\n' +
95-
' 1 error and 0 warnings potentially fixable with the `--fix` option.\n',
96-
]),
92+
message:
93+
'\n' +
94+
'/workspaces/angular-eslint-stylelint-builder/test/src/autofixable.ts\n' +
95+
" 8:10 error Unnecessary 'else' after 'return' eslint\tno-else-return\n" +
96+
'\n' +
97+
'/workspaces/angular-eslint-stylelint-builder/test/src/file.css\n' +
98+
' 1:1 error Unknown rule number-leading-zero stylelint\tnumber-leading-zero\n' +
99+
' 1:1 error Unknown rule string-quotes stylelint\tstring-quotes\n' +
100+
' 1:1 error Unknown rule no-extra-semicolons stylelint\tno-extra-semicolons\n' +
101+
' 15:5 error Unexpected empty block (block-no-empty) stylelint\tblock-no-empty\n' +
102+
' 5:10 error Unexpected invalid hex color "#ZZZZZZ" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
103+
' 20:10 error Unexpected invalid hex color "#12345G" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
104+
' 9:3 error Unexpected duplicate "font-size" (declaration-block-no-duplicate-properties) stylelint\tdeclaration-block-no-duplicate-properties\n' +
105+
' 6:23 error Unexpected duplicate font-family name Arial (font-family-no-duplicate-names) stylelint\tfont-family-no-duplicate-names\n' +
106+
' 2:13 error Unexpected unit (length-zero-no-unit) stylelint\tlength-zero-no-unit\n' +
107+
' 3:13 error Unexpected unit (length-zero-no-unit) stylelint\tlength-zero-no-unit\n' +
108+
' 8:3 error Unexpected unknown property "font-weigth" (property-no-unknown) stylelint\tproperty-no-unknown\n' +
109+
' 19:1 error Unexpected unknown type selector "foo" (selector-type-no-unknown) stylelint\tselector-type-no-unknown\n' +
110+
' 12:13 error Unexpected unknown unit "pixels" (unit-no-unknown) stylelint\tunit-no-unknown\n' +
111+
'\n' +
112+
'/workspaces/angular-eslint-stylelint-builder/test/src/file.ts\n' +
113+
" 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" +
114+
'\n' +
115+
'✖ 15 problems (15 errors, 0 warnings)\n 1 error and 0 warnings potentially fixable with the `--fix` option.\n',
97116
},
98117
{
99118
level: 'error',
@@ -125,15 +144,11 @@ describe('Lint', () => {
125144
)
126145
.toPromise();
127146

128-
// The "result" member (of type BuilderOutput) is the next output.
129147
await run.result;
130-
131-
// Stop the builder from running. This stops Architect from keeping
132-
// the builder-associated states in memory, since builders keep waiting
133-
// to be scheduled.
134148
await run.stop();
135149
logger.complete();
136150

151+
// After autofix, expect all stylelint errors to remain (since most are not autofixable)
137152
expect(loggerPromise).resolves.toEqual([
138153
{
139154
level: 'info',
@@ -149,13 +164,24 @@ describe('Lint', () => {
149164
},
150165
{
151166
level: 'info',
152-
// @ts-ignore
153-
message: expect.toIncludeMultiple([
154-
//file.ts
155-
'file.ts\n' + " 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n",
156-
// info messages
157-
'✖ 1 problem (1 error, 0 warnings)\n',
158-
]),
167+
message:
168+
'\n' +
169+
'/workspaces/angular-eslint-stylelint-builder/test/src/file.css\n' +
170+
' 1:1 error Unknown rule number-leading-zero stylelint\tnumber-leading-zero\n' +
171+
' 1:1 error Unknown rule string-quotes stylelint\tstring-quotes\n' +
172+
' 1:1 error Unknown rule no-extra-semicolons stylelint\tno-extra-semicolons\n' +
173+
' 15:5 error Unexpected empty block (block-no-empty) stylelint\tblock-no-empty\n' +
174+
' 5:10 error Unexpected invalid hex color "#ZZZZZZ" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
175+
' 20:10 error Unexpected invalid hex color "#12345G" (color-no-invalid-hex) stylelint\tcolor-no-invalid-hex\n' +
176+
' 6:23 error Unexpected duplicate font-family name Arial (font-family-no-duplicate-names) stylelint\tfont-family-no-duplicate-names\n' +
177+
' 8:3 error Unexpected unknown property "font-weigth" (property-no-unknown) stylelint\tproperty-no-unknown\n' +
178+
' 19:1 error Unexpected unknown type selector "foo" (selector-type-no-unknown) stylelint\tselector-type-no-unknown\n' +
179+
' 12:13 error Unexpected unknown unit "pixels" (unit-no-unknown) stylelint\tunit-no-unknown\n' +
180+
'\n' +
181+
'/workspaces/angular-eslint-stylelint-builder/test/src/file.ts\n' +
182+
" 3:3 error Unexpected 'debugger' statement eslint\tno-debugger\n" +
183+
'\n' +
184+
'✖ 11 problems (11 errors, 0 warnings)\n',
159185
},
160186
{
161187
level: 'error',

lib/builder/src/eslint/eslint-linter.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,12 @@ export async function createESlintInstance(workspaceRoot: string, options: Schem
3535
const configPath = options.eslintConfig ? resolve(workspaceRoot, options.eslintConfig) : undefined;
3636

3737
const eslintOptions: ESLint.Options = {
38-
useEslintrc: !options.noEslintrc,
38+
// Removed: useEslintrc, ignorePath, resolvePluginsRelativeTo, rulePaths
3939
overrideConfigFile: configPath,
40-
ignorePath: options.eslintIgnorePath || undefined,
4140
fix: !!options.fix,
4241
cache: !!options.eslintCache,
43-
cacheLocation: options.eslintCacheLocation || undefined,
44-
cacheStrategy: options.eslintCacheStrategy || undefined,
45-
resolvePluginsRelativeTo: options.eslintResolvePluginsRelativeTo || undefined,
46-
rulePaths: options.eslintRulesDir || [],
42+
cacheLocation: options.eslintCacheLocation ?? undefined,
43+
cacheStrategy: options.eslintCacheStrategy ?? undefined,
4744
/**
4845
* Default is `true` and if not overridden the eslint.lintFiles() method will throw an error
4946
* when no target files are found.

lib/builder/src/stylelint/stylelint-linter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BuilderContext } from '@angular-devkit/architect';
22
import type { ESLint } from 'eslint';
3-
import type { LinterOptions } from 'stylelint';
3+
import type { LinterOptions } from 'stylelint/types/stylelint';
44

55
import type { Schema } from '../schema';
66
import { join, resolve, normalize } from 'path';

lib/builder/src/stylelint/stylelint-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { ESLint } from 'eslint';
22
import type stylelint from 'stylelint';
3-
import type { LinterResult } from 'stylelint';
3+
import type { LinterResult } from 'stylelint/types/stylelint';
44

55
export async function loadStylelint(): Promise<typeof stylelint> {
66
try {

package.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "Angular CLI builder for ESLint and stylelint",
55
"author": "André Kremser",
66
"license": "MIT",
7+
"type": "module",
78
"watch": {
89
"build": {
910
"patterns": [
@@ -15,7 +16,7 @@
1516
"scripts": {
1617
"preinstall": "npx only-allow pnpm",
1718
"build": "npm run clean && tsc -p tsconfig.lib.json && npm run copy:root && npm run copy:schema",
18-
"test": "jest --ci --coverage --no-colors",
19+
"test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --ci --coverage --no-colors",
1920
"copy:schema": "cp lib/builder/src/schema.json out/dist",
2021
"copy:root": "cp lib/builder/package.json lib/builder/builders.json LICENSE README.md out",
2122
"lint": "eslint ./lib/",
@@ -31,27 +32,27 @@
3132
"yarn": ">= 1.13.0"
3233
},
3334
"devDependencies": {
34-
"@angular-devkit/architect": "^0.1502.1",
35+
"@angular-devkit/architect": "^0.2000.0",
3536
"@semantic-release/changelog": "^6.0.2",
3637
"@semantic-release/git": "^10.0.1",
3738
"@types/jest": "^29.4.0",
38-
"@types/node": "^18.14.6",
39-
"@typescript-eslint/eslint-plugin": "^5.54.1",
40-
"@typescript-eslint/parser": "^5.54.1",
41-
"eslint": "^8.35.0",
42-
"eslint-config-prettier": "^8.7.0",
39+
"@types/node": "^22.15.29",
40+
"@typescript-eslint/eslint-plugin": "^8.33.1",
41+
"@typescript-eslint/parser": "^8.33.1",
42+
"eslint": "^9.28.0",
43+
"eslint-config-prettier": "^10.1.5",
4344
"eslint-plugin-import": "^2.27.5",
44-
"eslint-plugin-prettier": "^4.2.1",
45-
"eslint-plugin-unused-imports": "^2.0.0",
45+
"eslint-plugin-prettier": "^5.4.1",
46+
"eslint-plugin-unused-imports": "^4.1.4",
4647
"jest": "^29.5.0",
47-
"jest-extended": "^3.2.4",
48+
"jest-extended": "^5.0.3",
4849
"jest-github-actions-reporter": "^1.0.3",
4950
"jest-junit": "^16.0.0",
50-
"npm-watch": "^0.11.0",
51-
"prettier": "^2.8.4",
52-
"semantic-release": "^20.1.1",
53-
"stylelint": "^15.2.0",
51+
"npm-watch": "^0.13.0",
52+
"prettier": "^3.5.3",
53+
"semantic-release": "^24.2.5",
54+
"stylelint": "^16.20.0",
5455
"ts-jest": "^29.0.5",
55-
"typescript": "^4.9.5"
56+
"typescript": "^5.8.3"
5657
}
5758
}

0 commit comments

Comments
 (0)