Skip to content

Commit

Permalink
chore: enable eslint-plugin-perfectionist on typescript-eslint package (
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Aug 24, 2024
1 parent 9d97f34 commit d4f6943
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,13 @@ export default tseslint.config(
},
{
extends: [perfectionistPlugin.configs['recommended-alphabetical']],
ignores: ['packages/typescript-eslint/src/configs/*'],
files: [
'packages/ast-spec/{src,tests,typings}/**/*.ts',
'packages/integration-tests/{tests,tools,typing}/**/*.ts',
'packages/parser/{src,tests}/**/*.ts',
'packages/rule-tester/{src,tests,typings}/**/*.ts',
'packages/typescript-eslint/{src,tests}/**/*.ts',
'packages/utils/src/**/*.ts',
'packages/visitor-keys/src/**/*.ts',
'packages/website*/src/**/*.ts',
Expand Down
6 changes: 4 additions & 2 deletions packages/typescript-eslint/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pluginBase from '@typescript-eslint/eslint-plugin';
import * as parserBase from '@typescript-eslint/parser';
// see the comment in config-helper.ts for why this doesn't use /ts-eslint
import type { TSESLint } from '@typescript-eslint/utils';

import pluginBase from '@typescript-eslint/eslint-plugin';
import * as parserBase from '@typescript-eslint/parser';

import type { ConfigWithExtends } from './config-helper';

import { config } from './config-helper';
import allConfig from './configs/all';
import baseConfig from './configs/base';
Expand Down
27 changes: 14 additions & 13 deletions packages/typescript-eslint/tests/configs.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import rules from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules';
import type {
FlatConfig,
RuleRecommendation,
} from '@typescript-eslint/utils/ts-eslint';

import rules from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules';

import plugin from '../src/index';

const RULE_NAME_PREFIX = '@typescript-eslint/';
Expand Down Expand Up @@ -37,14 +38,14 @@ function filterRules(

interface FilterAndMapRuleConfigsSettings {
excludeDeprecated?: boolean;
typeChecked?: 'exclude' | 'include-only';
recommendations?: (RuleRecommendation | undefined)[];
typeChecked?: 'exclude' | 'include-only';
}

function filterAndMapRuleConfigs({
excludeDeprecated,
typeChecked,
recommendations,
typeChecked,
}: FilterAndMapRuleConfigsSettings = {}): [string, unknown][] {
let result = Object.entries(rules);

Expand Down Expand Up @@ -149,8 +150,8 @@ describe('recommended.ts', () => {
const configRules = filterRules(unfilteredConfigRules);
// note: include deprecated rules so that the config doesn't change between major bumps
const ruleConfigs = filterAndMapRuleConfigs({
typeChecked: 'exclude',
recommendations: ['recommended'],
typeChecked: 'exclude',
});

expect(entriesToObject(ruleConfigs)).toEqual(entriesToObject(configRules));
Expand Down Expand Up @@ -183,8 +184,8 @@ describe('recommended-type-checked-only.ts', () => {
const configRules = filterRules(unfilteredConfigRules);
// note: include deprecated rules so that the config doesn't change between major bumps
const ruleConfigs = filterAndMapRuleConfigs({
typeChecked: 'include-only',
recommendations: ['recommended'],
typeChecked: 'include-only',
}).filter(([ruleName]) => ruleName);

expect(entriesToObject(ruleConfigs)).toEqual(entriesToObject(configRules));
Expand All @@ -201,8 +202,8 @@ describe('strict.ts', () => {
// note: exclude deprecated rules, this config is allowed to change between minor versions
const ruleConfigs = filterAndMapRuleConfigs({
excludeDeprecated: true,
typeChecked: 'exclude',
recommendations: ['recommended', 'strict'],
typeChecked: 'exclude',
});

expect(entriesToObject(ruleConfigs)).toEqual(entriesToObject(configRules));
Expand Down Expand Up @@ -235,8 +236,8 @@ describe('strict-type-checked-only.ts', () => {
// note: exclude deprecated rules, this config is allowed to change between minor versions
const ruleConfigs = filterAndMapRuleConfigs({
excludeDeprecated: true,
typeChecked: 'include-only',
recommendations: ['recommended', 'strict'],
typeChecked: 'include-only',
}).filter(([ruleName]) => ruleName);

expect(entriesToObject(ruleConfigs)).toEqual(entriesToObject(configRules));
Expand All @@ -252,8 +253,8 @@ describe('stylistic.ts', () => {
const configRules = filterRules(unfilteredConfigRules);
// note: include deprecated rules so that the config doesn't change between major bumps
const ruleConfigs = filterAndMapRuleConfigs({
typeChecked: 'exclude',
recommendations: ['stylistic'],
typeChecked: 'exclude',
});

expect(entriesToObject(ruleConfigs)).toEqual(entriesToObject(configRules));
Expand Down Expand Up @@ -285,8 +286,8 @@ describe('stylistic-type-checked-only.ts', () => {
const configRules = filterRules(unfilteredConfigRules);
// note: include deprecated rules so that the config doesn't change between major bumps
const ruleConfigs = filterAndMapRuleConfigs({
typeChecked: 'include-only',
recommendations: ['stylistic'],
typeChecked: 'include-only',
}).filter(([ruleName]) => ruleName);

expect(entriesToObject(ruleConfigs)).toEqual(entriesToObject(configRules));
Expand All @@ -300,23 +301,23 @@ describe('config helper', () => {
expect(
plugin.config({
files: ['file'],
rules: { rule: 'error' },
ignores: ['ignored'],
rules: { rule: 'error' },
}),
).toEqual([
{
files: ['file'],
rules: { rule: 'error' },
ignores: ['ignored'],
rules: { rule: 'error' },
},
]);
});

it('flattens extended configs', () => {
expect(
plugin.config({
rules: { rule: 'error' },
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
rules: { rule: 'error' },
}),
).toEqual([
{ rules: { rule1: 'error' } },
Expand All @@ -328,10 +329,10 @@ describe('config helper', () => {
it('flattens extended configs with files and ignores', () => {
expect(
plugin.config({
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
files: ['common-file'],
ignores: ['common-ignored'],
rules: { rule: 'error' },
extends: [{ rules: { rule1: 'error' } }, { rules: { rule2: 'error' } }],
}),
).toEqual([
{
Expand Down

0 comments on commit d4f6943

Please sign in to comment.