Skip to content

Commit

Permalink
fix eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
morewings committed Dec 2, 2023
1 parent 8aecf63 commit 32624bf
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 141 deletions.
6 changes: 3 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,9 @@ ij_shell_switch_cases_indented = false
ij_shell_use_unix_line_separator = true

[{*.cjs,*.js,*.js }]
indent_size = 2
tab_width = 2
ij_continuation_indent_size = 2
indent_size = 4
tab_width = 4
ij_continuation_indent_size = 4
ij_visual_guides = 80
ij_javascript_align_imports = false
ij_javascript_align_multiline_array_initializer_expression = false
Expand Down
259 changes: 122 additions & 137 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,146 +1,131 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
parserOptions: {
ecmaVersion: 'latest',
tsconfigRootDir: __dirname,
sourceType: 'module',
project: './tsconfig.linter.json',
},
settings: {
react: {
version: 'detect'
root: true,
env: {browser: true, es2020: true},
parserOptions: {
ecmaVersion: 'latest',
// eslint-disable-next-line no-undef
tsconfigRootDir: __dirname,
sourceType: 'module',
project: './tsconfig.linter.json',
},
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:ssr-friendly/recommended',
'plugin:storybook/recommended',
'plugin:prettier/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['import', 'prettier', '@typescript-eslint', 'ssr-friendly', 'react-refresh'],
rules: {
/**
* Allow empty arrow functions `() => {}`, while keeping other empty functions restricted
* @see https://eslint.org/docs/latest/rules/no-empty-function#allow-arrowfunctions
*/
'@typescript-eslint/no-empty-function': [
'error',
{allow: ['arrowFunctions']},
],
'@typescript-eslint/ban-ts-comment': 1,
'no-const-assign': 'error',
/** Restrict imports from devDependencies since they are not included in library build. peerDependencies are ok */
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: false,
peerDependencies: true,
},
settings: {
react: {
version: 'detect',
},
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:ssr-friendly/recommended',
'plugin:storybook/recommended',
'plugin:prettier/recommended',
],
/**
* Enforce import order with empty lines between import group
* @see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
*/
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
['parent', 'sibling', 'index'],
parser: '@typescript-eslint/parser',
plugins: ['import', 'prettier', '@typescript-eslint', 'ssr-friendly', 'react-refresh'],
rules: {
/**
* Allow empty arrow functions `() => {}`, while keeping other empty functions restricted
* @see https://eslint.org/docs/latest/rules/no-empty-function#allow-arrowfunctions
*/
'@typescript-eslint/no-empty-function': ['error', {allow: ['arrowFunctions']}],
'@typescript-eslint/ban-ts-comment': 1,
'no-const-assign': 'error',
/** Restrict imports from devDependencies since they are not included in library build. peerDependencies are ok */
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: false,
peerDependencies: true,
},
],
pathGroups: [
{
pattern: '@/**',
group: 'internal',
},
/**
* Enforce import order with empty lines between import group
* @see https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md
*/
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
pathGroups: [
{
pattern: '@/**',
group: 'internal',
},
],
'newlines-between': 'always',
},
],
'newlines-between': 'always',
},
],
/**
* Disallow combined module and type imports like this `import React, {FC} from 'react'`.
* Eslint will try to split into type and module imports instead
* @see https://typescript-eslint.io/rules/consistent-type-imports/
*/
'@typescript-eslint/consistent-type-imports': 'error',
'import/no-cycle': 'error',
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'@typescript-eslint/consistent-type-definitions': [
'error',
'type'
]
},
overrides: [
/* Allow require imports for internal scripts */
{
files: ['*.js', '*.cjs'],
rules: {
'@typescript-eslint/no-var-requires': 0,
},
},
/* Allow devDependencies imports for tests and config files */
{
files: [
'**/*.spec.*',
'**/testUtils/*.*',
'**/*.js',
'**/*.cjs',
'**/setupTests.ts',
'**/*.stories.*',
'vite.config.ts'
],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
peerDependencies: true,
},
/**
* Disallow combined module and type imports like this `import React, {FC} from 'react'`.
* Eslint will try to split into type and module imports instead
* @see https://typescript-eslint.io/rules/consistent-type-imports/
*/
'@typescript-eslint/consistent-type-imports': 'error',
'import/no-cycle': 'error',
'prettier/prettier': [
'error',
{
semi: true,
singleQuote: true,
jsxSingleQuote: false,
trailingComma: 'es5',
bracketSpacing: false,
jsxBracketSameLine: true,
arrowParens: 'avoid',
},
],
},
'react-refresh/only-export-components': ['warn', {allowConstantExport: true}],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
},
/* Disable `environment` directory imports for library files */
{
files: ['./src/lib/**/*.*'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/environment/**'],
message:
'Imports from environment directory are forbidden in the library files.',
},
overrides: [
/* Allow require imports for internal scripts */
{
files: ['*.js', '*.cjs'],
rules: {
'@typescript-eslint/no-var-requires': 0,
},
},
/* Allow devDependencies imports for tests and config files */
{
files: [
'**/*.spec.*',
'**/testUtils/*.*',
'**/*.js',
'**/*.cjs',
'**/setupTests.ts',
'**/*.stories.*',
'vite.config.ts',
],
},
],
},
},
],
rules: {
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true,
peerDependencies: true,
},
],
},
},
/* Disable `environment` directory imports for library files */
{
files: ['./src/lib/**/*.*'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
{
group: ['**/environment/**'],
message: 'Imports from environment directory are forbidden in the library files.',
},
],
},
],
},
},
],
};

2 changes: 1 addition & 1 deletion tsconfig.linter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends" : "./tsconfig.json",
"include": ["**/*.stories.tsx", "**/*.stories.ts", "*.config.ts", "src"],
"include": ["**/*.stories.tsx", "**/*.stories.ts", "*.config.ts", "src", ".eslintrc.cjs"],
"exclude": ["./dist/**"]
}

0 comments on commit 32624bf

Please sign in to comment.