-
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.
feat: add more eslint config presets
Allows us to use the eslint configs more flexibly. Upgrades the quality generator to allow selecting which preset - required for NX cypress project usage.
- Loading branch information
Showing
15 changed files
with
438 additions
and
46 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
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
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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import type { Linter } from 'eslint'; | ||
|
||
import { rootConfigsOverrides } from '../overrides/rootConfigs'; | ||
import { scriptsOverrides } from '../overrides/scripts'; | ||
import { testOverrides } from '../overrides/tests'; | ||
import { emotionRules } from '../rules/emotion'; | ||
import { generalRules } from '../rules/general'; | ||
import { promiseRules } from '../rules/promise'; | ||
|
||
if (!process.env.NODE_ENV) { | ||
// This check allows us to run linters inside IDE's | ||
process.env.NODE_ENV = 'development'; | ||
} | ||
|
||
module.exports = { | ||
extends: ['airbnb', 'plugin:eslint-comments/recommended', 'prettier'], | ||
|
||
plugins: ['eslint-comments', 'promise', '@tablecheck', '@nx', '@emotion'], | ||
|
||
parserOptions: { | ||
ecmaVersion: 'latest', | ||
sourceType: 'module', | ||
}, | ||
|
||
env: { | ||
node: true, | ||
browser: true, | ||
commonjs: true, | ||
es6: true, | ||
}, | ||
|
||
rules: { | ||
...generalRules, | ||
...promiseRules, | ||
...emotionRules, | ||
}, | ||
|
||
overrides: [ | ||
rootConfigsOverrides, | ||
scriptsOverrides, | ||
testOverrides, | ||
{ | ||
files: [ | ||
'**/__fixtures__/**/*', | ||
'**/*.fixture.{ts,tsx,js,jsx,cts,mts,cjs,mjs}', | ||
'**/*.{stories,story}.{ts,tsx,js,jsx}', | ||
'.storybook/**/*.{ts,tsx,js,jsx}', | ||
], | ||
rules: { | ||
'no-console': 'off', | ||
'import/no-default-export': 'off', | ||
'react-hooks/rules-of-hooks': 'off', | ||
'react-hooks/exhaustive-deps': 'off', | ||
'react/function-component-definition': 'off', | ||
'react/jsx-no-constructed-context-values': 'off', | ||
'react-refresh/only-export-components': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/naming-convention': 'off', | ||
'@typescript-eslint/ban-ts-comment': 'off', | ||
'consistent-return': 'error', | ||
}, | ||
env: { | ||
node: true, | ||
}, | ||
}, | ||
], | ||
} satisfies Linter.Config; |
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,43 @@ | ||
import type { Linter } from 'eslint'; | ||
|
||
import { testOverrides as testRules } from '../overrides/tests'; | ||
import { namingRules } from '../rules/namingConvention'; | ||
|
||
if (!process.env.NODE_ENV) { | ||
// This check allows us to run linters inside IDE's | ||
process.env.NODE_ENV = 'development'; | ||
} | ||
|
||
const testOverrides = Object.keys(testRules.rules ?? {}).reduce( | ||
(result, ruleKey) => ({ ...result, [ruleKey]: 'off' }), | ||
{}, | ||
); | ||
|
||
module.exports = { | ||
env: { | ||
'cypress/globals': true, | ||
}, | ||
rules: { | ||
...testOverrides, | ||
'promise/catch-or-return': 'off', | ||
'promise/always-return': 'off', | ||
'import/no-import-module-exports': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-namespace': 'off', | ||
'@typescript-eslint/naming-convention': ( | ||
['error'] as Linter.RuleLevelAndOptions | ||
).concat( | ||
( | ||
namingRules[ | ||
'@typescript-eslint/naming-convention' | ||
] as Linter.RuleLevelAndOptions | ||
).slice(1), | ||
[ | ||
{ | ||
selector: 'memberLike', | ||
format: null, | ||
}, | ||
], | ||
) as Linter.RuleLevelAndOptions, | ||
}, | ||
} satisfies Linter.Config; |
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,15 @@ | ||
import type { Linter } from 'eslint'; | ||
|
||
if (!process.env.NODE_ENV) { | ||
// This check allows us to run linters inside IDE's | ||
process.env.NODE_ENV = 'development'; | ||
} | ||
|
||
module.exports = { | ||
overrides: [ | ||
{ | ||
files: ['**/cypress/**/*', '**/*.{cy,cypress}.{js,jsx,ts,tsx}'], | ||
extends: ['@tablecheck/eslint-config/preset-cypress'], | ||
}, | ||
], | ||
} satisfies Linter.Config; |
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,41 @@ | ||
import * as path from 'path'; | ||
|
||
import type { Linter } from 'eslint'; | ||
import * as fs from 'fs-extra'; | ||
import type { PackageJson } from 'type-fest'; | ||
|
||
import { reactRules } from '../rules/react'; | ||
|
||
if (!process.env.NODE_ENV) { | ||
// This check allows us to run linters inside IDE's | ||
process.env.NODE_ENV = 'development'; | ||
} | ||
|
||
let reactVersion = '17'; // set to 17 for legacy reasons or to not error if react not present - should be able to detect below | ||
const packageJsonPath = path.resolve(path.join(process.cwd(), 'package.json')); | ||
if (fs.existsSync(packageJsonPath)) { | ||
const pkg = fs.readJsonSync(packageJsonPath) as PackageJson; | ||
if (pkg.dependencies?.react) { | ||
const versionOnly = pkg.dependencies.react | ||
.replace(/^[^0-9]+/gi, '') | ||
.replace(/\..+$/gi, ''); | ||
if (versionOnly === '*') | ||
reactVersion = '18'; // dumb hack, but using '*' is more dumb | ||
else if (!Number.isNaN(parseFloat(versionOnly))) reactVersion = versionOnly; | ||
} | ||
} | ||
|
||
module.exports = { | ||
plugins: ['react-refresh'], | ||
extends: ['plugin:react-hooks/recommended'], | ||
|
||
settings: { | ||
react: { | ||
version: reactVersion, | ||
}, | ||
}, | ||
|
||
rules: { | ||
...reactRules, | ||
}, | ||
} satisfies Linter.Config; |
Oops, something went wrong.