Skip to content

Feature/flat config #114

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

Merged
merged 3 commits into from
Jun 20, 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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,21 @@
[![Paypal Donate](https://img.shields.io/badge/Donate-paypal-blue.svg?style=flat-square&logo=paypal&colorA=cccccc)](https://acel.me/donate)

Coding standard used by Shlink JavaScript projects.

This library includes two ESLint configurations, the base one, and the react-specific one. Default export includes both:

```js
// eslint.config.js
import shlink from '@shlinkio/eslint-config-js-coding-standard';

export default shlink;
```

If the project does not use React, you can just use the base config:

```js
// eslint.config.js
import { baseConfig } from '@shlinkio/eslint-config-js-coding-standard';

export default baseConfig;
```
182 changes: 109 additions & 73 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,79 +1,115 @@
module.exports = {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended'
],
plugins: ['jsx-a11y', 'simple-import-sort', '@stylistic'],
parserOptions: {
ecmaFeatures: {
jsx: true
}
},
settings: {
react: {
version: 'detect'
}
},
rules: {
'@stylistic/arrow-parens': 'error',
'@stylistic/arrow-spacing': 'error',
'@stylistic/block-spacing': 'error',
'@stylistic/comma-dangle': ['error', 'always-multiline'],
'@stylistic/eol-last': 'error',
'@stylistic/function-call-spacing': 'error',
'@stylistic/indent': ['error', 2],
'@stylistic/key-spacing': 'error',
'@stylistic/keyword-spacing': 'error',
'@stylistic/max-len': [
'error',
// Do not allow more than 120 characters per line, except for long strings and comments in the same line
{ 'code': 120, 'ignoreComments': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true },
import eslint from '@eslint/js';
import stylistic from '@stylistic/eslint-plugin';
import pluginJsxA11y from 'eslint-plugin-jsx-a11y';
import react from 'eslint-plugin-react';
import eslintPluginReactHooks from 'eslint-plugin-react-hooks';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import tseslint from 'typescript-eslint';

export const baseConfig = tseslint.config(
{
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
],
'@stylistic/no-trailing-spaces': 'error',
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/quotes': ['error', 'single'],
'@stylistic/jsx-quotes': ['error', 'prefer-double'],
'@stylistic/rest-spread-spacing': 'error',
'@stylistic/semi': 'error',
'@stylistic/spaced-comment': 'error',
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1 }],
plugins: {
'@stylistic': stylistic,
'simple-import-sort': simpleImportSort,
},
rules: {
'@stylistic/arrow-parens': 'error',
'@stylistic/arrow-spacing': 'error',
'@stylistic/block-spacing': 'error',
'@stylistic/comma-dangle': ['error', 'always-multiline'],
'@stylistic/eol-last': 'error',
'@stylistic/function-call-spacing': 'error',
'@stylistic/indent': ['error', 2],
'@stylistic/key-spacing': 'error',
'@stylistic/keyword-spacing': 'error',
'@stylistic/max-len': [
'error',
// Do not allow more than 120 characters per line, except for long strings and comments in the same line
{ 'code': 120, 'ignoreComments': true, 'ignoreStrings': true, 'ignoreTemplateLiterals': true },
],
'@stylistic/no-trailing-spaces': 'error',
'@stylistic/object-curly-spacing': ['error', 'always'],
'@stylistic/quotes': ['error', 'single'],
'@stylistic/jsx-quotes': ['error', 'prefer-double'],
'@stylistic/rest-spread-spacing': 'error',
'@stylistic/semi': 'error',
'@stylistic/spaced-comment': 'error',
'@stylistic/no-multiple-empty-lines': ['error', { 'max': 1 }],

'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/consistent-type-imports': 'error',

'simple-import-sort/imports': ['error', {
'groups': [
// First external imports, then local imports, then styles imports
['^', '^\\.', '\\.s?css$']
]
}],
'no-restricted-exports': ['error', {
'restrictDefaultExports': {
'direct': true,
'named': true,
'defaultFrom': true,
'namedFrom': true,
'namespaceFrom': true
}
}],
'simple-import-sort/imports': ['error', {
'groups': [
// First external imports, then local imports, then styles imports
['^', '^\\.', '\\.s?css$']
]
}],
'no-restricted-exports': ['error', {
'restrictDefaultExports': {
'direct': true,
'named': true,
'defaultFrom': true,
'namedFrom': true,
'namespaceFrom': true
}
}],

// Disabled rules from presets
'react/display-name': ['off', { 'ignoreTranspilerName': false }],
'react/prop-types': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-explicit-any': 'off'
// Disabled rules from presets
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
},
{
files: ['*.test.*', '*.spec.*'],
rules: {
'prefer-promise-reject-errors': 'off',
'no-param-reassign': 'off',
'@typescript-eslint/no-shadow': 'off',
},
},
overrides: [
{
files: ['*.test.*', '*.spec.*'],
rules: {
'prefer-promise-reject-errors': 'off',
'no-param-reassign': 'off',
'react/no-children-prop': 'off',
'@typescript-eslint/no-shadow': 'off'
);

export const reactConfig = tseslint.config(
{
plugins: {
'jsx-a11y': pluginJsxA11y,
react,
'react-hooks': eslintPluginReactHooks,
},
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
settings: {
react: {
version: 'detect'
}
}
]
};
},
rules: {
...pluginJsxA11y.configs.recommended.rules,
...eslintPluginReactHooks.configs.recommended.rules,

// Disabled rules from presets
'react/display-name': ['off', { 'ignoreTranspilerName': false }],
'react/prop-types': 'off',
},
},
{
files: ['*.test.*', '*.spec.*'],
rules: {
'react/no-children-prop': 'off',
},
},
);

export default tseslint.config(
...baseConfig,
...reactConfig,
);
Loading