Skip to content

Commit

Permalink
Add a legacy version of the configs for users who are not yet ready t…
Browse files Browse the repository at this point in the history
…o move to eslint v9
  • Loading branch information
Pewtro committed Jul 25, 2024
1 parent c4f617d commit 09c9036
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-seahorses-wait.md
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
2 changes: 1 addition & 1 deletion packages/eslint-config-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@types/eslint__js": "8.42.3"
},
"peerDependencies": {
"eslint": "^9.7.0",
"eslint": "^8.57.0 || ^9.7.0",
"typescript": "^5"
},
"scripts": {
Expand Down
11 changes: 10 additions & 1 deletion packages/eslint-config-typescript/src/index.ts
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 };
88 changes: 88 additions & 0 deletions packages/eslint-config-typescript/src/legacy-base.ts
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',
},
};
7 changes: 7 additions & 0 deletions packages/eslint-config-typescript/src/legacy-recommended.ts
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'],
};

0 comments on commit 09c9036

Please sign in to comment.