Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(shared): add shared eslint config #1447

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions common/shared/eslint/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
exports.baseRules = {
curly: ['error', 'multi-line'],
'import/no-cycle': 'error',
'import/no-self-import': 'error',
'ts/no-explicit-any': 'warn',
'style/brace-style': ['warn', '1tbs', { allowSingleLine: true }],
'style/comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
enums: 'always-multiline',
functions: 'never',
}],
'style/arrow-parens': ['error', 'always'],
'ts/no-redeclare': 'off',
'antfu/if-newline': 'off',
'style/spaced-comment': 'off',
'tunicorn/number-literal-case': 'off',
'style/indent-binary-ops': 'off',
'ts/method-signature-style': 'off',
'style/indent': ['error', 4, {
ObjectExpression: 'first',
SwitchCase: 1,
ignoreComments: true,
}],
'sort-imports': [
'error',
{
allowSeparatedGroups: false,
// ignoreCase: false,
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
},
],

// TODO: debatable rules
'test/prefer-lowercase-title': 'off',
'antfu/top-level-function': 'off',
'style/operator-linebreak': 'off',
'unicorn/no-new-array': 'off',
'unicorn/prefer-includes': 'off',
'prefer-arrow-callback': 'off',
'no-restricted-globals': 'off',
'unicorn/prefer-string-starts-ends-with': 'warn',

// TODO: just for compatibility with old code
'unused-imports/no-unused-vars': 'warn',
'style/jsx-closing-tag-location': 'warn',
'ts/ban-types': 'warn',
'unicorn/prefer-dom-node-text-content': 'warn',
'unicorn/prefer-number-properties': 'warn',
'no-prototype-builtins': 'warn',
'style/no-tabs': 'warn',
'style/quotes': ['warn', 'single', { avoidEscape: true }],

'react/display-name': 'off',
'react-hooks/rules-of-hooks': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'ts/prefer-ts-expect-error': 'off',
'ts/ban-ts-comment': 'off',
'ts/no-duplicate-enum-values': 'off',
'no-cond-assign': 'warn',
'antfu/consistent-list-newline': 'off',
'ts/no-use-before-define': 'warn',
'intunicorn/number-literal-case': 'off',
'test/no-identical-title': 'warn',
'ts/no-non-null-asserted-optional-chain': 'warn',
'no-restricted-syntax': 'warn',
'prefer-regex-literals': 'warn',
'ts/no-this-alias': 'warn',
'prefer-promise-reject-errors': 'warn',
'no-new': 'warn',
'unicorn/error-message': 'warn',
'ts/prefer-literal-enum-member': 'warn',
'style/jsx-curly-newline': ['warn', { multiline: 'forbid', singleline: 'forbid' }],
'no-control-regex': 'warn',
'style/jsx-wrap-multilines': 'warn',
'ts/no-import-type-side-effects': 'warn',
'style/quote-props': ['warn', 'as-needed'],
'unicorn/number-literal-case': 'warn',
'react/no-direct-mutation-state': 'warn',
'style/jsx-curly-brace-presence': 'warn',
'style/multiline-ternary': 'warn',
'unicorn/prefer-type-error': 'warn',
'accessor-pairs': 'warn',
};

exports.typescriptPreset = function typescriptPreset() {
return {
files: ['**/*.ts', '**/*.tsx'],
rules: {
'ts/naming-convention': [
'warn',
// Interfaces' names should start with a capital 'I'.
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z0-9]',
match: true,
},
},
// Private fields of a class should start with an underscore '_'.
{
selector: ['classMethod', 'classProperty'],
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'require',
},
],
},
languageOptions: {
parser: require('@typescript-eslint/parser'),
},
};
};
7 changes: 4 additions & 3 deletions common/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
},
"keywords": [],
"exports": {
"./tsconfigs/*.json": "./tsconfigs/*",
"./eslint": "./eslint/index.js",
"./tsconfigs/*": "./tsconfigs/*.json",
"./vite": "./vite/index.js"
},
"dependencies": {
"@typescript-eslint/parser": "^7.1.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-istanbul": "^1.3.0",
"@vitest/coverage-istanbul": "^1.3.1",
"happy-dom": "^13.3.8",
"vite": "^5.1.4",
"vite-plugin-dts": "^3.7.2",
"vite-plugin-dts": "^3.7.3",
"vitest": "^1.3.1"
}
}
121 changes: 4 additions & 117 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import antfu from '@antfu/eslint-config';
import header from 'eslint-plugin-header';
import tsParser from '@typescript-eslint/parser';
import { baseRules, typescriptPreset } from '@univerjs/shared/eslint';

export default antfu({
stylistic: {
Expand All @@ -14,99 +14,12 @@ export default antfu({
},
},
markdown: false,
typescript: true,
formatters: {
css: true,
html: true,
// markdown: 'prettier'
},
rules: {
curly: ['error', 'multi-line'],
'import/no-cycle': 'error',
'ts/no-explicit-any': 'warn',
'style/brace-style': ['warn', '1tbs', { allowSingleLine: true }],
'style/comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'always-multiline',
enums: 'always-multiline',
functions: 'never',
}],
'style/arrow-parens': ['error', 'always'],
'ts/no-redeclare': 'off',
'antfu/if-newline': 'off',
'style/spaced-comment': 'off',
'tunicorn/number-literal-case': 'off',
'style/indent-binary-ops': 'off',
'ts/method-signature-style': 'off',
'style/indent': ['error', 4, {
ObjectExpression: 'first',
SwitchCase: 1,
ignoreComments: true,
}],
'sort-imports': [
'error',
{
allowSeparatedGroups: false,
// ignoreCase: false,
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
},
],

// TODO: debatable rules
'test/prefer-lowercase-title': 'off',
'antfu/top-level-function': 'off',
'style/operator-linebreak': 'off',
'unicorn/no-new-array': 'off',
'unicorn/prefer-includes': 'off',
'prefer-arrow-callback': 'off',
'no-restricted-globals': 'off',
'unicorn/prefer-string-starts-ends-with': 'warn',

// TODO: just for compatibility with old code
'unused-imports/no-unused-vars': 'warn',
'style/jsx-closing-tag-location': 'warn',
'ts/ban-types': 'warn',
'unicorn/prefer-dom-node-text-content': 'warn',
'unicorn/prefer-number-properties': 'warn',
'no-prototype-builtins': 'warn',
'style/no-tabs': 'warn',
'style/quotes': ['warn', 'single', { avoidEscape: true }],

'react/display-name': 'off',
'react-hooks/rules-of-hooks': 'off',
'eslint-comments/no-unlimited-disable': 'off',
'ts/prefer-ts-expect-error': 'off',
'ts/ban-ts-comment': 'off',
'ts/no-duplicate-enum-values': 'off',
'no-cond-assign': 'warn',
'antfu/consistent-list-newline': 'off',
'ts/no-use-before-define': 'warn',
'intunicorn/number-literal-case': 'off',
'test/no-identical-title': 'warn',
'ts/no-non-null-asserted-optional-chain': 'warn',
'no-restricted-syntax': 'warn',
'prefer-regex-literals': 'warn',
'ts/no-this-alias': 'warn',
'prefer-promise-reject-errors': 'warn',
'no-new': 'warn',
'unicorn/error-message': 'warn',
'ts/prefer-literal-enum-member': 'warn',
'style/jsx-curly-newline': ['warn', { multiline: 'forbid', singleline: 'forbid' }],
'no-control-regex': 'warn',
'style/jsx-wrap-multilines': 'warn',
'ts/no-import-type-side-effects': 'warn',
'style/quote-props': ['warn', 'as-needed'],
'unicorn/number-literal-case': 'warn',
'react/no-direct-mutation-state': 'warn',
'style/jsx-curly-brace-presence': 'warn',
'style/multiline-ternary': 'warn',
'unicorn/prefer-type-error': 'warn',
'accessor-pairs': 'warn',
},
rules: baseRules,
}, {
files: ['**/*.ts', '**/*.tsx'],
ignores: ['**/*.d.ts', '**/vite.config.ts', 'playwright.config.ts'],
Expand Down Expand Up @@ -137,30 +50,4 @@ export default antfu({
2,
],
},
}, {
files: ['**/*.ts', '**/*.tsx'],
rules: {
'ts/naming-convention': [
'warn',
// Interfaces' names should start with a capital 'I'.
{
selector: 'interface',
format: ['PascalCase'],
custom: {
regex: '^I[A-Z0-9]',
match: true,
},
},
// Private fields of a class should start with an underscore '_'.
{
selector: ['classMethod', 'classProperty'],
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'require',
},
],
},
languageOptions: {
parser: tsParser,
},
});
}, typescriptPreset());
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
"@storybook/testing-library": "^0.2.2",
"@types/node": "^20.11.19",
"@types/react": "^18.2.57",
"@typescript-eslint/parser": "^7.0.2",
"@univerjs/design": "workspace:*",
"@univerjs/shared": "workspace:*",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint-plugin-format": "^0.1.0",
Expand Down
Loading
Loading