@stordata/eslint-config
Version:
Shareable ESLint configuration for Stordata projects
167 lines (165 loc) • 5.14 kB
JavaScript
import js from '@eslint/js';
import n from 'eslint-plugin-n';
import noOnlyTests from 'eslint-plugin-no-only-tests';
import stylistic from '@stylistic/eslint-plugin';
import globals from 'globals';
import jsxAccessibility from 'eslint-plugin-jsx-a11y';
export default [
n.configs['flat/recommended'],
stylistic.configs.customize({
semi: true,
braceStyle: '1tbs',
commaDangle: 'never',
quoteProps: 'as-needed'
}),
{
files: [
'**/*.?(c|m){j,t}s?(x)'
],
plugins: {
js,
'@stylistic': stylistic
},
rules: {
...js.configs.recommended.rules,
// Stuff we cherry-picked from Airbnb style guide
'@stylistic/multiline-ternary': 'off',
'@stylistic/no-confusing-arrow': ['error', { allowParens: true }],
'@stylistic/no-extra-parens': ['error', 'all', {
ignoreJSX: 'all',
nestedBinaryExpressions: false,
ignoredNodes: ['ArrowFunctionExpression[body.type=ConditionalExpression]']
}],
'@stylistic/operator-linebreak': 'off',
'@stylistic/quotes': ['error', 'single', { avoidEscape: true }],
eqeqeq: 'error',
'guard-for-in': 'error',
'no-alert': 'error',
'no-console': 'warn',
'no-else-return': ['error', { allowElseIf: false }],
'no-eval': 'error',
'no-extend-native': 'error',
'no-extra-bind': 'error',
'no-floating-decimal': 'error',
'no-implied-eval': 'error',
'no-lone-blocks': 'error',
'no-param-reassign': ['error', {
props: true,
ignorePropertyModificationsFor: [
'acc', // for reduce accumulators
'accumulator', // for reduce accumulators
'req', // for Express requests
'res', // for Express responses
'instance' // For sequelize instances (in hooks for instance)
]
}],
'no-return-assign': 'error',
'no-var': 'error',
'object-shorthand': ['error', 'always', { ignoreConstructors: false, avoidQuotes: true }],
'one-var-declaration-per-line': ['error', 'always'],
'prefer-const': ['error', { destructuring: 'any' }],
'prefer-template': 'error',
yoda: 'error',
// Stordata overrides
'@stylistic/indent': ['error', 2, {
VariableDeclarator: {
let: 2,
const: 3
},
SwitchCase: 1
}],
'@stylistic/jsx-one-expression-per-line': 'off',
'@stylistic/jsx-curly-brace-presence': ['error', { props: 'always', children: 'ignore', propElementValues: 'always' }],
'@stylistic/padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' }, // newline-before-return
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' } // newline-after-var
],
'@stylistic/padded-blocks': 'off',
'@stylistic/space-before-function-paren': ['error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'never',
catch: 'always'
}],
'n/no-process-exit': 'off',
'no-unused-vars': ['error', { argsIgnorePattern: 'next' }],
'one-var': ['error', 'consecutive'],
strict: ['error', 'safe'],
// Not sure about these
// They come from n/flat/recommended config, but there are lots of errors for packages that _apparently_ are published
'n/no-unpublished-import': 'off',
'n/no-unpublished-require': 'off'
}
},
{
files: [
'**/*.{j,t}sx'
],
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
},
plugins: {
'jsx-a11y': jsxAccessibility
},
rules: {
// Picked from eslint-config-react-app (CRA)
'jsx-a11y/alt-text': 'warn',
'jsx-a11y/anchor-has-content': 'warn',
'jsx-a11y/anchor-is-valid': ['warn', { aspects: ['noHref', 'invalidHref'] }],
'jsx-a11y/aria-activedescendant-has-tabindex': 'warn',
'jsx-a11y/aria-props': 'warn',
'jsx-a11y/aria-proptypes': 'warn',
'jsx-a11y/aria-role': ['warn', { ignoreNonDOM: true }],
'jsx-a11y/aria-unsupported-elements': 'warn',
'jsx-a11y/heading-has-content': 'warn',
'jsx-a11y/iframe-has-title': 'warn',
'jsx-a11y/img-redundant-alt': 'warn',
'jsx-a11y/no-access-key': 'warn',
'jsx-a11y/no-distracting-elements': 'warn',
'jsx-a11y/no-redundant-roles': 'warn',
'jsx-a11y/role-has-required-aria-props': 'warn',
'jsx-a11y/role-supports-aria-props': 'warn',
'jsx-a11y/scope': 'warn'
}
},
{
files: [
'**/*.test.?(c|m){j,t}s?(x)',
'**/*.spec.?(c|m){j,t}s?(x)',
'**/setupTests?(.*).{j,t}s?(x)'
],
plugins: {
'no-only-tests': noOnlyTests
},
languageOptions: {
globals: {
...globals.mocha,
...globals.vitest
}
},
rules: {
'no-only-tests/no-only-tests': 'error'
}
},
{
files: [
'**/*.c{j,t}s?(x)'
],
languageOptions: {
sourceType: 'commonjs'
}
},
{
files: [
'**/*.m{j,t}s?(x)'
],
languageOptions: {
sourceType: 'module'
}
}
];