Skip to content

Commit

Permalink
migrate normal custom rules (#236)
Browse files Browse the repository at this point in the history
Signed-off-by: Kangrui Johann Ye <[email protected]>
  • Loading branch information
strawberry-choco authored Oct 7, 2024
1 parent da60a0f commit 5722c41
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 69 deletions.
4 changes: 1 addition & 3 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export default tseslint.config(
'packages/eslint-plugin-typescript/src/configs/recommended-json/*',
'packages/eslint-plugin-typescript/src/configs/recommended-package/*',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/recommended-typescript.config.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/custom.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/format.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/import.ts',
'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/rxjs.ts',
'packages/eslint-plugin-typescript/src/rules/*',
'packages/eslint-plugin-typescript/src/util/*',
'packages/eslint-plugin-typescript/src/rules/ts-config/*',
'scripts/*',
'.eslintrc.format.js',
'eslint.config.mjs',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {TSESLint} from '@typescript-eslint/utils';

import {NoMomentJsRuleName} from '../../../rules/no-moment-js';
import {NoOnEventAssignName} from '../../../rules/no-on-event-assign';
import {NoMomentJsRuleName} from '../../../rules/typescript/no-moment-js';
import {NoOnEventAssignName} from '../../../rules/typescript/no-on-event-assign';

const pluginPrefix = '@cloudflight/typescript';

Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-plugin-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ import pluginJs from '@eslint/js';
import tseslint from 'typescript-eslint';
import {eslintRules} from './configs/recommended-typescript/rules/eslint';
import {typescriptEslintRules} from './configs/recommended-typescript/rules/typescript-eslint';
import {customRules} from './configs/recommended-typescript/rules/custom';
import {cloudflightTypescriptPlugin} from './rules';

export const config = tseslint.config(
{
files: ['**/*.{js,mjs,cjs,ts,mts,cts}'],
ignores: ['jest.config*.ts'],
plugins: {
'@cloudflight/typescript': cloudflightTypescriptPlugin,
},
extends: [
pluginJs.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
],
rules: {
...eslintRules,
...typescriptEslintRules,
...customRules,
}
},
{
Expand Down
89 changes: 29 additions & 60 deletions packages/eslint-plugin-typescript/src/rules/index.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,34 @@
import {TSESLint} from '@typescript-eslint/utils';
import {NoMomentJsRule, NoMomentJsRuleName} from './typescript/no-moment-js';
import {NoOnEventAssign, NoOnEventAssignName} from './typescript/no-on-event-assign';

import {
PackageForceAbsoluteVersionDependenciesRule,
PackageForceAbsoluteVersionDependenciesRuleName,
} from './package/package-force-absolute-version-dependencies.rule';
import {PackageForcePrivateRule, PackageForcePrivateRuleName} from './package/package-force-private.rule';
import {
TscAllowUnreachableCodeRule,
TscAllowUnreachableCodeRuleName,
} from './ts-config/tsc-allow-unreachable-code.rule';
import {TscAllowUnusedLabelsRule, TscAllowUnusedLabelsRuleName} from './ts-config/tsc-allow-unused-labels.rule';
import {TscEsModuleInteropRule, TscEsModuleInteropRuleName} from './ts-config/tsc-es-module-interop.rule';
import {
TscForceConsistentCasingInFileNamesRule,
TscForceConsistentCasingInFileNamesRuleName,
} from './ts-config/tsc-force-consistent-casing-in-file-names.rule';
import {TscImportHelpersRule, TscImportHelpersRuleName} from './ts-config/tsc-import-helpers.rule';
import {
TscImportsNotUsedAsValuesRule,
TscImportsNotUsedAsValuesRuleName,
} from './ts-config/tsc-imports-not-used-as-values.rule';
import {TscIsolatedModulesRule, TscIsolatedModulesRuleName} from './ts-config/tsc-isolated-modules.rule';
import {
TscNoFallThroughCasesInSwitchRule,
TscNoFallThroughCasesInSwitchRuleName,
} from './ts-config/tsc-no-fall-through-cases-in-switch.rule';
import {TscNoImplicitOverrideRule, TscNoImplicitOverrideRuleName} from './ts-config/tsc-no-implicit-override.rule';
import {TscNoImplicitReturnsRule, TscNoImplicitReturnsRuleName} from './ts-config/tsc-no-implicit-returns.rule';
import {
TscNoPropertyAccessFromIndexSignatureRule,
TscNoPropertyAccessFromIndexSignatureRuleName,
} from './ts-config/tsc-no-property-access-from-index-signature.rule';
import {
TscNoUncheckedIndexedAccessRule,
TscNoUncheckedIndexedAccessRuleName,
} from './ts-config/tsc-no-unchecked-indexed-access.rule';
import {TscStrictRule, TscStrictRuleName} from './ts-config/tsc-strict.rule';
import {
TscUseDefineForClassFieldsRule,
TscUseDefineForClassFieldsRuleName,
} from './ts-config/tsc-use-define-for-class-fields.rule';
import {NoMomentJsRule, NoMomentJsRuleName} from './no-moment-js';
import {NoOnEventAssign, NoOnEventAssignName} from './no-on-event-assign';

export const rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>> = {
[PackageForcePrivateRuleName]: PackageForcePrivateRule,
[PackageForceAbsoluteVersionDependenciesRuleName]: PackageForceAbsoluteVersionDependenciesRule,
[TscAllowUnreachableCodeRuleName]: TscAllowUnreachableCodeRule,
[TscAllowUnusedLabelsRuleName]: TscAllowUnusedLabelsRule,
[TscEsModuleInteropRuleName]: TscEsModuleInteropRule,
[TscForceConsistentCasingInFileNamesRuleName]: TscForceConsistentCasingInFileNamesRule,
[TscImportHelpersRuleName]: TscImportHelpersRule,
[TscImportsNotUsedAsValuesRuleName]: TscImportsNotUsedAsValuesRule,
[TscIsolatedModulesRuleName]: TscIsolatedModulesRule,
[TscNoFallThroughCasesInSwitchRuleName]: TscNoFallThroughCasesInSwitchRule,
[TscNoImplicitOverrideRuleName]: TscNoImplicitOverrideRule,
[TscNoImplicitReturnsRuleName]: TscNoImplicitReturnsRule,
[TscNoPropertyAccessFromIndexSignatureRuleName]: TscNoPropertyAccessFromIndexSignatureRule,
[TscNoUncheckedIndexedAccessRuleName]: TscNoUncheckedIndexedAccessRule,
[TscStrictRuleName]: TscStrictRule,
[TscUseDefineForClassFieldsRuleName]: TscUseDefineForClassFieldsRule,
const rules: Record<string, TSESLint.RuleModule<string, readonly unknown[]>> = {
// todo: eslint-plugin-json-es is not compatible with eslint v9 as of writing
// and will be migrated later
// [PackageForcePrivateRuleName]: PackageForcePrivateRule,
// [PackageForceAbsoluteVersionDependenciesRuleName]: PackageForceAbsoluteVersionDependenciesRule,
// [TscAllowUnreachableCodeRuleName]: TscAllowUnreachableCodeRule,
// [TscAllowUnusedLabelsRuleName]: TscAllowUnusedLabelsRule,
// [TscEsModuleInteropRuleName]: TscEsModuleInteropRule,
// [TscForceConsistentCasingInFileNamesRuleName]: TscForceConsistentCasingInFileNamesRule,
// [TscImportHelpersRuleName]: TscImportHelpersRule,
// [TscImportsNotUsedAsValuesRuleName]: TscImportsNotUsedAsValuesRule,
// [TscIsolatedModulesRuleName]: TscIsolatedModulesRule,
// [TscNoFallThroughCasesInSwitchRuleName]: TscNoFallThroughCasesInSwitchRule,
// [TscNoImplicitOverrideRuleName]: TscNoImplicitOverrideRule,
// [TscNoImplicitReturnsRuleName]: TscNoImplicitReturnsRule,
// [TscNoPropertyAccessFromIndexSignatureRuleName]: TscNoPropertyAccessFromIndexSignatureRule,
// [TscNoUncheckedIndexedAccessRuleName]: TscNoUncheckedIndexedAccessRule,
// [TscStrictRuleName]: TscStrictRule,
// [TscUseDefineForClassFieldsRuleName]: TscUseDefineForClassFieldsRule,
[NoMomentJsRuleName]: NoMomentJsRule,
[NoOnEventAssignName]: NoOnEventAssign,
};

export const cloudflightTypescriptPlugin: TSESLint.FlatConfig.Plugin = {
meta: {
name: '@cloudflight/typescript',
version: 'see package.json file',
},
rules,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createRule} from '../util/create-rule';
import {createRule} from '../../util/create-rule';

export const NoMomentJsRuleName = 'no-moment-js';
/**
Expand All @@ -12,7 +12,6 @@ export const NoMomentJsRule = createRule<[], 'noMomentJs'>({
fixable: 'code',
docs: {
description: 'Enforces that all packages have absolute versions.',
recommended: 'strict',
},
schema: [],
messages: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createRule} from '../util/create-rule';
import {createRule} from '../../util/create-rule';

const disallowedEvents = [
'onabort',
Expand Down Expand Up @@ -106,7 +106,6 @@ export const NoOnEventAssign = createRule<[], 'noAssign'>({
fixable: 'code',
docs: {
description: 'Enforces that all packages have absolute versions.',
recommended: 'strict',
},
schema: [],
messages: {
Expand Down

0 comments on commit 5722c41

Please sign in to comment.