Skip to content

Commit 2eebcba

Browse files
committed
Autofix lint warnings
1 parent 3bb6897 commit 2eebcba

16 files changed

+87
-82
lines changed

scripts/docs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ async function generateConfigDocs(config, allConfigs, peerDeps) {
149149
return [otherName, otherRuleIds];
150150
}),
151151
);
152-
const extendedRuleIds = Object.values(extendedConfigs).flat();
152+
const extendedRuleIds = new Set(Object.values(extendedConfigs).flat());
153153

154154
const ruleIds = getAllEnabledRuleIds(config.flatConfig).filter(
155-
ruleId => !extendedRuleIds.includes(ruleId),
155+
ruleId => !extendedRuleIds.has(ruleId),
156156
);
157157

158158
const eslint = new ESLint();
@@ -194,7 +194,7 @@ async function generateConfigDocs(config, allConfigs, peerDeps) {
194194
id,
195195
);
196196
const testLevel =
197-
testEntry != null ? ruleLevelFromEntry(testEntry) : null;
197+
testEntry == null ? null : ruleLevelFromEntry(testEntry);
198198

199199
return {
200200
id,

scripts/helpers/configs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ const configExtraPatterns = {
5858
};
5959

6060
/** @type {(keyof typeof configDescriptions)[]} */
61-
const testConfigs = [
61+
const testConfigs = new Set([
6262
'jest',
6363
'vitest',
6464
'cypress',
6565
'playwright',
6666
'react-testing-library',
67-
];
67+
]);
6868

6969
const tsConfigDocsReference = md`Refer to ${md.link('./typescript.md#🏗️-setup', "step 3 in TypeScript config's setup docs")} for how to set up tsconfig properly.`;
7070

@@ -280,7 +280,7 @@ export function configExtraPattern(name) {
280280
*/
281281
export function isConfigForTests(name) {
282282
// @ts-expect-error the point is to check if string is a union
283-
return testConfigs.includes(name);
283+
return testConfigs.has(name);
284284
}
285285

286286
/**

scripts/helpers/format-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function optionsPreview(options) {
235235
*/
236236
function truncate(text, max) {
237237
if (text.length > max) {
238-
return text.slice(0, max - 3) + '...';
238+
return `${text.slice(0, max - 3) }...`;
239239
}
240240
return text;
241241
}
@@ -244,5 +244,5 @@ function truncate(text, max) {
244244
* @param {string} content
245245
*/
246246
function sanitizeRuleOptions(content) {
247-
return content.replace(/\\/g, '\\\\').replace(/\*/g, '\\*');
247+
return content.replace(/\\/g, '\\\\').replace(/\*/g, String.raw`\*`);
248248
}

scripts/helpers/format-readme.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ function mermaidDiagram(nodes, edges, orientation = 'TD') {
131131
.map(node => ` ${node.id}("${node.label}")`),
132132
...edges.map(
133133
edge =>
134-
' ' +
134+
` ${
135135
[edge.from, edge.label ? `--${edge.label}-->` : '-->', edge.to].join(
136136
' ',
137-
),
137+
)}`,
138138
),
139139
].join('\n');
140140
}

src/configs/vitest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default tseslint.config({
3838
// https://github.com/veritem/eslint-plugin-vitest#rules
3939
'vitest/consistent-test-filename': [
4040
'warn',
41-
{ pattern: '.*\\.spec\\.[tj]sx?$' },
41+
{ pattern: String.raw`.*\.spec\.[tj]sx?$` },
4242
],
4343
'vitest/consistent-test-it': 'warn',
4444
'vitest/max-nested-describe': ['warn', { max: 2 }],

src/lib/utils.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@
66
* @returns {import('eslint').Linter.RulesRecord}
77
*/
88
export function convertErrorsToWarnings(rules) {
9-
return Object.entries(rules).reduce(
10-
(acc, [ruleId, entry]) => ({
11-
...acc,
12-
[ruleId]: entry === 'error' || entry === 2 ? 'warn' : entry,
13-
}),
14-
{},
15-
);
9+
return Object.fromEntries(Object.entries(rules).map(
10+
( [ruleId, entry]) => [ruleId, entry === 'error' || entry === 2 ? 'warn' : entry],
11+
));
1612
}

tests/configs/angular.spec.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,63 @@ describe('angular config', () => {
77
const { setup, teardown, loadConfig } = createLintUtils('angular');
88

99
beforeAll(setup);
10+
1011
afterAll(teardown);
1112

12-
test('should load config for TypeScript file', async () => {
13+
it('should load config for TypeScript file', async () => {
1314
await expect(loadConfig('src/app/app.component.ts')).resolves.not.toThrow();
1415
});
1516

16-
test('should load config for HTML file', async () => {
17+
it('should load config for HTML file', async () => {
1718
await expect(
1819
loadConfig('src/app/app.component.html'),
1920
).resolves.not.toThrow();
2021
});
2122

22-
test('should not include template rules for non-HTML file', async () => {
23+
it('should not include template rules for non-HTML file', async () => {
2324
const config = await loadConfig('src/app/app.component.ts');
2425
expect(Object.keys(config.rules ?? {}).join(',')).not.toContain(
2526
'@angular-eslint/template/',
2627
);
2728
});
2829

29-
test('should have explicitly added rule for TS file', async () => {
30+
it('should have explicitly added rule for TS file', async () => {
3031
const config = await loadConfig('src/app/app.component.ts');
3132
expect(config.rules).toHaveProperty(
3233
'@angular-eslint/prefer-on-push-component-change-detection',
3334
);
3435
});
3536

36-
test('should have explicitly added rule for HTML file', async () => {
37+
it('should have explicitly added rule for HTML file', async () => {
3738
const config = await loadConfig('src/app/app.component.html');
3839
expect(config.rules).toHaveProperty('@angular-eslint/template/no-any');
3940
});
4041

41-
test('should have rule from extended typescript config', async () => {
42+
it('should have rule from extended typescript config', async () => {
4243
const config = await loadConfig('src/app/app.component.ts');
4344
expect(config.rules).toHaveProperty(
4445
'@typescript-eslint/no-non-null-assertion',
4546
);
4647
});
4748

48-
test('should have rule from extended recommended angular config', async () => {
49+
it('should have rule from extended recommended angular config', async () => {
4950
const config = await loadConfig('src/app/app.component.ts');
5051
expect(config.rules).toHaveProperty('@angular-eslint/contextual-lifecycle');
5152
});
5253

53-
test('should have rule from extended recommended angular template config', async () => {
54+
it('should have rule from extended recommended angular template config', async () => {
5455
const config = await loadConfig('src/app/app.component.html');
5556
expect(config.rules).toHaveProperty(
5657
'@angular-eslint/template/banana-in-box',
5758
);
5859
});
5960

60-
test('should have rule from extended angular template accessibility config', async () => {
61+
it('should have rule from extended angular template accessibility config', async () => {
6162
const config = await loadConfig('src/app/app.component.html');
6263
expect(config.rules).toHaveProperty('@angular-eslint/template/alt-text');
6364
});
6465

65-
test('should have rule disabled if test file pattern matches', async () => {
66+
it('should have rule disabled if test file pattern matches', async () => {
6667
const config = await loadConfig(
6768
'src/app/components/accordion/accordion.component.stories.ts',
6869
);

tests/configs/graphql.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,29 @@ describe('graphql config', () => {
1010
);
1111

1212
beforeAll(setup);
13+
1314
afterAll(teardown);
1415

15-
test('should have graphql plugin rules for GraphQL file', async () => {
16+
it('should have graphql plugin rules for GraphQL file', async () => {
1617
const config = await loadConfig('src/schema.graphql');
1718
expect(Object.keys(config.rules ?? {}).join(',')).toContain(
1819
'@graphql-eslint/',
1920
);
2021
});
2122

22-
test('should have rule from extended schema config', async () => {
23+
it('should have rule from extended schema config', async () => {
2324
const config = await loadConfig();
2425
expect(config.rules).toHaveProperty('@graphql-eslint/naming-convention');
2526
});
2627

27-
test('should have rule from extended relay config', async () => {
28+
it('should have rule from extended relay config', async () => {
2829
const config = await loadConfig();
2930
expect(config.rules).toHaveProperty(
3031
'@graphql-eslint/relay-connection-types',
3132
);
3233
});
3334

34-
test('should have customized rule', async () => {
35+
it('should have customized rule', async () => {
3536
const config = await loadConfig();
3637
expect(config.rules).toHaveProperty('@graphql-eslint/description-style');
3738
expect(config.rules?.['@graphql-eslint/description-style']).toEqual([

tests/configs/javascript.spec.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,59 @@ describe('javascript config', () => {
1010
);
1111

1212
beforeAll(setup);
13+
1314
afterAll(teardown);
1415

15-
test('should load config for JavaScript file', async () => {
16+
it('should load config for JavaScript file', async () => {
1617
await expect(loadConfig('index.js')).resolves.not.toThrow();
1718
});
1819

19-
test('should load config for TypeScript file', async () => {
20+
it('should load config for TypeScript file', async () => {
2021
await expect(loadConfig('src/utils.ts')).resolves.not.toThrow();
2122
});
2223

23-
test('should have explicitly added rule', async () => {
24+
it('should have explicitly added rule', async () => {
2425
const config = await loadConfig();
2526
expect(config.rules).toHaveProperty('eqeqeq');
2627
});
2728

28-
test('should have implicitly extended rule', async () => {
29+
it('should have implicitly extended rule', async () => {
2930
const config = await loadConfig();
3031
expect(config.rules).toHaveProperty('no-const-assign');
3132
});
3233

33-
test('should not include any rule which requires type checking', async () => {
34+
it('should not include any rule which requires type checking', async () => {
3435
const rules = await loadRules();
3536
const rulesWithTypes = Object.entries(rules)
3637
.filter(([, meta]) => meta.docs?.['requiresTypeChecking'])
3738
.map(([ruleId]) => ruleId);
3839
expect(rulesWithTypes).toHaveLength(0);
3940
});
4041

41-
test('should have rule disabled if test file pattern matches', async () => {
42+
it('should have rule disabled if test file pattern matches', async () => {
4243
const config = await loadConfig('utils.spec.js');
4344
expect(config.rules?.['@typescript-eslint/no-non-null-assertion']).toEqual([
4445
0,
4546
]);
4647
});
4748

48-
test('should have rule disabled if known config file pattern matches', async () => {
49+
it('should have rule disabled if known config file pattern matches', async () => {
4950
const config = await loadConfig('jest.config.ts');
5051
expect(config.rules?.['import/no-anonymous-default-export']).toEqual([0]);
5152
});
5253

53-
test('should have rule disabled if generated file pattern matches', async () => {
54+
it('should have rule disabled if generated file pattern matches', async () => {
5455
const config = await loadConfig(
5556
'src/graphql/generated/introspection-result.ts',
5657
);
5758
expect(config.rules?.['unicorn/no-abusive-eslint-disable']).toEqual([0]);
5859
});
5960

60-
test('should not throw when linting project without tsconfig', async () => {
61+
it('should not throw when linting project without tsconfig', async () => {
6162
await expect(lint(['*.js'])).resolves.not.toThrow();
6263
});
6364

64-
test('should only warn for all unicorn plugin rules', async () => {
65+
it('should only warn for all unicorn plugin rules', async () => {
6566
const config = await loadConfig();
6667
const unicornErrorRules = Object.entries(config.rules ?? {})
6768
.filter(([ruleId]) => ruleId.startsWith('unicorn/'))

tests/configs/jest.spec.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,30 @@ describe('jest config', () => {
77
const { setup, teardown, loadConfig } = createLintUtils('jest', '*.spec.ts');
88

99
beforeAll(setup);
10+
1011
afterAll(teardown);
1112

12-
test('should not include jest rules for non-test file', async () => {
13+
it('should not include jest rules for non-test file', async () => {
1314
const config = await loadConfig('lib/auth.ts');
1415
expect(Object.keys(config?.rules ?? {}).join(',')).not.toContain('jest/');
1516
});
1617

17-
test('should include jest rules for test file', async () => {
18+
it('should include jest rules for test file', async () => {
1819
const config = await loadConfig('__test__/auth.spec.js');
1920
expect(Object.keys(config.rules ?? {}).join(',')).toContain('jest/');
2021
});
2122

22-
test('should have rule from extended recommended jest config', async () => {
23+
it('should have rule from extended recommended jest config', async () => {
2324
const config = await loadConfig();
2425
expect(config.rules).toHaveProperty('jest/no-identical-title');
2526
});
2627

27-
test('should have explicitly added rule', async () => {
28+
it('should have explicitly added rule', async () => {
2829
const config = await loadConfig();
2930
expect(config.rules).toHaveProperty('jest/no-test-return-statement');
3031
});
3132

32-
test('should have customized severity level for rule from extended config', async () => {
33+
it('should have customized severity level for rule from extended config', async () => {
3334
const config = await loadConfig();
3435
expect(config.rules?.['jest/no-mocks-import']).toEqual([1]);
3536
});

tests/configs/ngrx.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,28 @@ describe('ngrx config', () => {
77
const { setup, teardown, loadConfig } = createLintUtils('ngrx', '*.ts');
88

99
beforeAll(setup);
10+
1011
afterAll(teardown);
1112

12-
test('should load config for TypeScript file', async () => {
13+
it('should load config for TypeScript file', async () => {
1314
await expect(
1415
loadConfig('src/app/store/auth.reducer.ts'),
1516
).resolves.not.toThrow();
1617
});
1718

18-
test('should have explicitly added rule', async () => {
19+
it('should have explicitly added rule', async () => {
1920
const config = await loadConfig();
2021
expect(config.rules).toHaveProperty('rxjs-x/no-unsafe-catch');
2122
});
2223

23-
test('should have rule from extended angular config', async () => {
24+
it('should have rule from extended angular config', async () => {
2425
const config = await loadConfig();
2526
expect(config.rules).toHaveProperty(
2627
'@angular-eslint/prefer-on-push-component-change-detection',
2728
);
2829
});
2930

30-
test('should have rule from extended recommended ngrx config', async () => {
31+
it('should have rule from extended recommended ngrx config', async () => {
3132
const config = await loadConfig();
3233
expect(config.rules).toHaveProperty('@ngrx/good-action-hygiene');
3334
});

tests/configs/node.spec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,24 @@ describe('node config', () => {
1010
);
1111

1212
beforeAll(setup);
13+
1314
afterAll(teardown);
1415

15-
test('should load config for JavaScript file', async () => {
16+
it('should load config for JavaScript file', async () => {
1617
await expect(loadConfig('src/utils.js')).resolves.not.toThrow();
1718
});
1819

19-
test('should have explicitly added rule', async () => {
20+
it('should have explicitly added rule', async () => {
2021
const config = await loadConfig();
2122
expect(config.rules).toHaveProperty('n/prefer-promises/fs');
2223
});
2324

24-
test('should have rule from extended base config', async () => {
25+
it('should have rule from extended base config', async () => {
2526
const config = await loadConfig();
2627
expect(config.rules).toHaveProperty('import/no-commonjs');
2728
});
2829

29-
test('should not include any rule which requires type checking', async () => {
30+
it('should not include any rule which requires type checking', async () => {
3031
const rules = await loadRules();
3132
const rulesWithTypes = Object.entries(rules)
3233
.filter(([, meta]) => meta.docs?.['requiresTypeChecking'])

0 commit comments

Comments
 (0)