Skip to content

Commit 9af8c85

Browse files
committed
feat(deps): update ESLint and Stylelint configurations, add support for Angular 16+, and improve builder options
1 parent 1f3f60f commit 9af8c85

21 files changed

+146
-123
lines changed

.eslintrc.json

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/integration-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
build:
1414
strategy:
1515
matrix:
16-
angular-version: [9, 10, 11, 12, 13, 14, 15]
16+
angular-version: [16,17,18,19,20]
1717
os: [ubuntu-latest, windows-latest]
1818

1919
runs-on: ${{ matrix.os }}
@@ -31,7 +31,7 @@ jobs:
3131
- name: 🏗 Setup node version
3232
uses: actions/setup-node@v3
3333
with:
34-
node-version: 18
34+
node-version: 22
3535
cache: 'pnpm'
3636
- run: |
3737
pnpm install --frozen-lockfile

.github/workflows/unit-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: 🏗 Setup node version
2424
uses: actions/setup-node@v3
2525
with:
26-
node-version: 18
26+
node-version: 22
2727
cache: 'pnpm'
2828

2929
- name: 🏗 Install dependencies

README.md

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Angular ESLint + Stylelint Linter
32

43
[![npm version](https://badge.fury.io/js/@krema%2Fangular-eslint-stylelint-builder.svg)](https://badge.fury.io/js/@krema%2Fangular-eslint-stylelint-builder) ![node workflow](https://github.com/krema/angular-eslint-stylelint-builder/actions/workflows/integration-test.yml/badge.svg) ![node workflow](https://github.com/krema/angular-eslint-stylelint-builder/actions/workflows/unit-test.yml/badge.svg) ![angular versions](https://img.shields.io/badge/angular-v9--v15-%2523DD0031.svg?flat-square&logo=angular&labelColor=ff0000&color=grey)
@@ -160,41 +159,22 @@ You can configure the following options:
160159
<td colspan="5"><b>File Enumeration:</b></td>
161160
</tr>
162161
<tr>
163-
<td>eslintIgnorePath</td>
164-
<td></td>
162+
<td>eslintIgnorePatterns</td>
163+
<td>[]</td>
165164
<td>
166-
A path to a file containing patterns describing files to ignore instead of
167-
$CWD/.eslintignore
165+
Array of glob patterns describing files to ignore (replaces <code>eslintIgnorePath</code> and <code>.eslintignore</code> in ESLint 9+)
168166
</td>
169167
<td></td>
170168
<td>eslint</td>
171169
</tr>
172170
<tr>
173-
<td>stylelintIgnorePath</td>
174-
<td></td>
175-
<td>
176-
A path to a file containing patterns describing files to ignore instead of
177-
$CWD/.stylelintignore
178-
</td>
179-
<td></td>
180-
<td>stylelint</td>
181-
</tr>
182-
<tr>
183-
<td>eslintRulesDir</td>
171+
<td>stylelintIgnorePatterns</td>
184172
<td>[]</td>
185173
<td>
186-
This option allows you to specify another directory from which to load
187-
rules files
174+
Array of glob patterns describing files to ignore (replaces <code>stylelintIgnorePath</code> and <code>.stylelintignore</code> in Stylelint 16+)
188175
</td>
189176
<td></td>
190-
<td>eslint</td>
191-
</tr>
192-
<tr>
193-
<td>eslintResolvePluginsRelativeTo</td>
194-
<td></td>
195-
<td>Changes the folder where plugins are resolved from</td>
196-
<td></td>
197-
<td>eslint</td>
177+
<td>stylelint</td>
198178
</tr>
199179
<tr>
200180
<td colspan="5"><b>Output:</b></td>

eslint.config.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import js from "@eslint/js";
2+
import tseslint from "@typescript-eslint/eslint-plugin";
3+
import tsParser from "@typescript-eslint/parser";
4+
import importPlugin from "eslint-plugin-import";
5+
import prettierPlugin from "eslint-plugin-prettier";
6+
import unusedImportsPlugin from "eslint-plugin-unused-imports";
7+
8+
export default [
9+
js.configs.recommended,
10+
{
11+
files: ["**/*.ts"],
12+
languageOptions: {
13+
parser: tsParser,
14+
parserOptions: {
15+
project: [
16+
"tsconfig.json",
17+
"tsconfig.lib.json",
18+
"tsconfig.spec.json"
19+
],
20+
createDefaultProgram: false,
21+
ecmaVersion: 2022,
22+
sourceType: "module"
23+
},
24+
globals: {
25+
NodeJS: "readonly",
26+
describe: "readonly",
27+
it: "readonly",
28+
beforeEach: "readonly",
29+
afterEach: "readonly",
30+
expect: "readonly",
31+
jest: "readonly",
32+
console: "readonly",
33+
process: "readonly"
34+
}
35+
},
36+
plugins: {
37+
"@typescript-eslint": tseslint,
38+
"unused-imports": unusedImportsPlugin,
39+
"prettier": prettierPlugin,
40+
"import": importPlugin
41+
},
42+
rules: {
43+
"prettier/prettier": "error",
44+
"@typescript-eslint/consistent-type-imports": "error",
45+
"@typescript-eslint/no-unused-vars": [
46+
"error",
47+
{
48+
argsIgnorePattern: "_"
49+
}
50+
],
51+
"@typescript-eslint/array-type": "error",
52+
"@typescript-eslint/ban-ts-comment": "off",
53+
"no-else-return": "error",
54+
"semi": ["error", "always"]
55+
},
56+
settings: {
57+
"import/resolver": {
58+
typescript: {}
59+
}
60+
}
61+
}
62+
];

lib/builder/src/builder.spec.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { toArray, map } from 'rxjs/operators';
2+
import { lastValueFrom } from 'rxjs';
23

34
import { Architect } from '@angular-devkit/architect';
45
import { TestingArchitectHost } from '@angular-devkit/architect/testing';
@@ -48,12 +49,14 @@ describe('Lint', () => {
4849
'@krema/angular-eslint-stylelint-builder:lint',
4950
{
5051
eslintFilePatterns: ['src/**/*.ts'],
52+
eslintConfig: 'eslint.config.js',
5153
stylelintFilePatterns: ['src/**/*.css'],
54+
stylelintConfig: 'stylelint.config.js',
5255
},
5356
{ logger: logger }
5457
);
55-
const loggerPromise = logger
56-
.pipe(
58+
const loggerPromise = lastValueFrom(
59+
logger.pipe(
5760
toArray(),
5861
map(messages =>
5962
messages.map(y => {
@@ -62,7 +65,7 @@ describe('Lint', () => {
6265
})
6366
)
6467
)
65-
.toPromise();
68+
);
6669

6770
// The "result" member (of type BuilderOutput) is the next output.
6871
await run.result;
@@ -127,13 +130,15 @@ describe('Lint', () => {
127130
'@krema/angular-eslint-stylelint-builder:lint',
128131
{
129132
eslintFilePatterns: ['src/**/*.ts'],
130-
stylelintFilePatterns: ['src/**/*.css'],
133+
eslintConfig: 'eslint.config.js',
131134
fix: true,
135+
stylelintFilePatterns: ['src/**/*.css'],
136+
stylelintConfig: 'stylelint.config.js',
132137
},
133138
{ logger }
134139
);
135-
const loggerPromise = logger
136-
.pipe(
140+
const loggerPromise = lastValueFrom(
141+
logger.pipe(
137142
toArray(),
138143
map(messages =>
139144
messages.map(y => {
@@ -142,7 +147,7 @@ describe('Lint', () => {
142147
})
143148
)
144149
)
145-
.toPromise();
150+
);
146151

147152
await run.result;
148153
await run.stop();
@@ -189,4 +194,37 @@ describe('Lint', () => {
189194
},
190195
]);
191196
});
197+
198+
it('ignores files matching eslintIgnorePatterns and stylelintIgnorePatterns', async () => {
199+
const run = await architect.scheduleBuilder(
200+
'@krema/angular-eslint-stylelint-builder:lint',
201+
{
202+
eslintFilePatterns: ['src/**/*.ts'],
203+
stylelintFilePatterns: ['src/**/*.css'],
204+
eslintIgnorePatterns: ['**/file.ts'],
205+
stylelintIgnorePatterns: ['**/file.css'],
206+
stylelintConfig: 'stylelint.config.js',
207+
},
208+
{ logger }
209+
);
210+
const loggerPromise = lastValueFrom(
211+
logger.pipe(
212+
toArray(),
213+
map(messages =>
214+
messages.map(y => {
215+
return { level: y.level, message: y.message };
216+
})
217+
)
218+
)
219+
);
220+
221+
await run.result;
222+
await run.stop();
223+
logger.complete();
224+
225+
// The output should not mention file.ts or file.css
226+
const output = JSON.stringify(await loggerPromise);
227+
expect(output).not.toContain('file.ts');
228+
expect(output).not.toContain('file.css');
229+
});
192230
});

lib/builder/src/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createESlintInstance } from './eslint/eslint-linter';
66
import { report } from './eslint/reporter';
77

88
export async function builder(options: Schema, context: BuilderContext): Promise<BuilderOutput> {
9-
const projectName = context?.target?.project || '<???>';
9+
const projectName = context?.target?.project ?? '<???>';
1010
const printInfo = options.format && !options.silent;
1111

1212
if (printInfo) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ 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-
// Removed: useEslintrc, ignorePath, resolvePluginsRelativeTo, rulePaths
3938
overrideConfigFile: configPath,
4039
fix: !!options.fix,
4140
cache: !!options.eslintCache,
@@ -49,6 +48,7 @@ export async function createESlintInstance(workspaceRoot: string, options: Schem
4948
* a project and therefore doesn't necessarily have matching files, for example.
5049
*/
5150
errorOnUnmatchedPattern: false,
51+
ignorePatterns: options.eslintIgnorePatterns ?? [],
5252
};
5353

5454
const projectESLint = await loadESLint();

lib/builder/src/eslint/reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function report(
3131
* "no results" case differently.
3232
*/
3333
const formatter = await eslintInstance.loadFormatter(options.format);
34-
const formattedResults = formatter.format(finalLintResults.lintResults);
34+
const formattedResults = await formatter.format(finalLintResults.lintResults);
3535
const printInfo = options.format && !options.silent;
3636
const maxWarnings = options.maxWarnings;
3737
const reportOnlyErrors = options.quiet;

lib/builder/src/schema.d.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { JsonObject } from '@angular-devkit/core';
22

3-
export type BuilderOptions = typeof Schema & JsonObject;
3+
export type BuilderOptions = Schema & JsonObject;
44

55
export interface Schema {
66
eslintFilePatterns: string[];
@@ -14,10 +14,8 @@ export interface Schema {
1414
eslintCacheLocation: string | null;
1515
stylelintCacheLocation: string | null;
1616
eslintCacheStrategy: 'content' | 'metadata' | null;
17-
eslintIgnorePath: string | null;
18-
stylelintIgnorePath: string | null;
19-
eslintRulesDir: string[];
20-
eslintResolvePluginsRelativeTo: string | null;
17+
eslintIgnorePatterns?: string[];
18+
stylelintIgnorePatterns?: string[];
2119
outputFile: string | null;
2220
format: Formatter;
2321
silent: boolean;

0 commit comments

Comments
 (0)