-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a legacy version of the configs for users who are not yet ready t…
…o move to eslint v9
- Loading branch information
Showing
6 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@putstack/eslint-config-typescript': minor | ||
--- | ||
|
||
Add a legacy version of the configs for users who are not yet ready to move to eslint v9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import { base } from './base'; | ||
import { baseLegacyConfig } from './legacy-base'; | ||
import { recommended } from './recommended'; | ||
|
||
type ConfigTypes = 'base' | 'recommended'; | ||
type LegacyConfigTypes = 'legacy/base' | 'legacy/recommended'; | ||
|
||
const configs: Record<ConfigTypes, TSESLint.FlatConfig.ConfigArray> = { | ||
const flatConfigs: Record<ConfigTypes, TSESLint.FlatConfig.ConfigArray> = { | ||
base, | ||
recommended, | ||
}; | ||
|
||
const legacyConfigs: Record<LegacyConfigTypes, TSESLint.ClassicConfig.Config> = { | ||
'legacy/base': baseLegacyConfig, | ||
'legacy/recommended': baseLegacyConfig, | ||
}; | ||
|
||
const configs = { ...flatConfigs, ...legacyConfigs }; | ||
|
||
export { configs }; | ||
export default { configs }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
|
||
export const baseLegacyConfig: TSESLint.ClassicConfig.Config = { | ||
extends: [ | ||
//General eslint recommended rules | ||
'eslint:recommended', | ||
//General typescript-eslint rules that have type knowledge | ||
'plugin:@typescript-eslint/recommended-type-checked', | ||
'plugin:@typescript-eslint/stylistic-type-checked', | ||
//General code quality rules | ||
'plugin:sonarjs/recommended', | ||
//General sorting rules (imports) | ||
'plugin:perfectionist/recommended-alphabetical-legacy', | ||
//General dependency rules to avoid tree bloat and redundant polyfills | ||
'plugin:depend/recommended', | ||
], | ||
parser: '@typescript-eslint/parser', | ||
plugins: ['@typescript-eslint', 'perfectionist', 'sonarjs', 'depend'], | ||
rules: { | ||
/** ESLint plugin configuration */ | ||
/** Stylistic rules */ | ||
//Prefer using Array<T> over T[] | ||
'@typescript-eslint/array-type': ['warn', { default: 'generic', readonly: 'generic' }], | ||
//We want to encourage marking type imports explicitly which is also enforced by TypeScripts --verbatimModuleSyntax | ||
'@typescript-eslint/consistent-type-imports': 'warn', | ||
//We want to encourage marking type exports explicitly | ||
'@typescript-eslint/consistent-type-exports': 'warn', | ||
//Enforce the use of top-level import type qualifer when an import only has specifiers with inline type qualifiers | ||
'@typescript-eslint/no-import-type-side-effects': 'warn', | ||
|
||
/** Code quality rules */ | ||
//Enforce default clauses in switch statements to be last | ||
'default-case-last': 'warn', | ||
//Disallow nested ternary expressions | ||
'no-nested-ternary': 'warn', | ||
//Prefer the arrow callback of ES6 where possible | ||
'prefer-arrow-callback': 'warn', | ||
|
||
/** Rules that need to be turned off in default eslint to be turned on in Typescript ESLint */ | ||
//Enforce default parameters to be last | ||
'@typescript-eslint/default-param-last': 'warn', | ||
'default-param-last': 'off', | ||
//Disallow variable declarations from shadowing variables declared in the outer scope | ||
'@typescript-eslint/no-shadow': 'warn', | ||
'no-shadow': 'off', | ||
//Disallow variable redeclaration | ||
'@typescript-eslint/no-redeclare': 'warn', | ||
'no-redeclare': 'off', | ||
|
||
//Emulate the TypeScript style of exempting names starting with _ | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
args: 'all', | ||
argsIgnorePattern: '^_', | ||
caughtErrors: 'all', | ||
caughtErrorsIgnorePattern: '^_', | ||
destructuredArrayIgnorePattern: '^_', | ||
ignoreRestSiblings: true, | ||
varsIgnorePattern: '^_', | ||
}, | ||
], | ||
|
||
//Set up a specific import order that we generally want to adhere to. | ||
//This makes it easier to recognize where an import is coming from. | ||
'perfectionist/sort-imports': [ | ||
'warn', | ||
{ | ||
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index', 'object', 'unknown'], | ||
ignoreCase: true, | ||
newlinesBetween: 'never', | ||
order: 'asc', | ||
type: 'alphabetical', | ||
}, | ||
], | ||
//If we have a list of objects, we want to sort them alphabetically, but we want to partition them by comments | ||
'perfectionist/sort-objects': [ | ||
'error', | ||
{ | ||
partitionByComment: true, | ||
}, | ||
], | ||
//Turning this rule off as recommended in the perfectionist documention as it is handled by perfectionist in the following rules: | ||
//sort-interfaces: https://eslint-plugin-perfectionist.azat.io/rules/sort-interfaces | ||
//sort-objects: https://eslint-plugin-perfectionist.azat.io/rules/sort-object-types | ||
'@typescript-eslint/adjacent-overload-signatures': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import { baseLegacyConfig } from './legacy-base'; | ||
|
||
export const recommendedLegacyConfig: TSESLint.ClassicConfig.Config = { | ||
...baseLegacyConfig, | ||
extends: [...(baseLegacyConfig.extends as Array<string>), 'plugin:unicorn/recommended'], | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.