Skip to content

Commit

Permalink
Merge pull request #47 from salute-developers/SPEED-1579-eslint-9-sup…
Browse files Browse the repository at this point in the history
…port

eslint flat config support
  • Loading branch information
pamellix authored Dec 26, 2024
2 parents 0945cf4 + 7e9a937 commit 70fddd4
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 1 deletion.
86 changes: 86 additions & 0 deletions packages/eslint-config-base/flat/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
'use strict';

import eslintRecommended from '@eslint/js';
import tsEslintRecommended from '@typescript-eslint/eslint-plugin';
import tsEslintParser from '@typescript-eslint/parser';
import importPlugin from 'eslint-plugin-import';

/** @type {import("eslint").Linter.Config[]} */
export default [
{
files: ['*.ts', '*.tsx'],
languageOptions: {
parser: tsEslintParser,
},
plugins: {
'@typescript-eslint': tsEslintRecommended,
import: importPlugin,
},
rules: {
...eslintRecommended.configs.recommended.rules,
...tsEslintRecommended.configs['eslint-recommended'].rules,
...tsEslintRecommended.configs.recommended.rules,
...importPlugin.configs.recommended.rules,

'@typescript-eslint/no-empty-function': 'off',
'no-restricted-syntax': 'off', // В for...of циклах ничего плохого нет
'spaced-comment': ['error', 'always', { markers: ['/'] }], // разрешаем ts-require directive
'comma-dangle': ['error', 'always-multiline'],
'arrow-parens': ['error', 'always'],

'space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
indent: 'off',
'max-len': [
'error',
120,
2,
{
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'if' },
],
'implicit-arrow-linebreak': 'off',
'no-plusplus': 'off',
'max-classes-per-file': 'off',
'operator-linebreak': 'off',
'object-curly-newline': 'off',
'class-methods-use-this': 'off',
'no-confusing-arrow': 'off',
'function-paren-newline': 'off',
'no-param-reassign': 'off',
'no-shadow': 'warn',
'consistent-return': 'off',

'@typescript-eslint/explicit-function-return-type': 'off',

'import/prefer-default-export': 'off', // @grape: https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/
'import/order': [
'error',
{
groups: [['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'always',
},
],
'import/no-unresolved': 'off',
'import/extensions': 'off',
'import/no-extraneous-dependencies': ['off'],
'arrow-body-style': 'off',
'no-unused-expressions': 'off',
},
},
];
71 changes: 71 additions & 0 deletions packages/eslint-config-base/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
export default {
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:import/recommended',
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/no-empty-function': 'off',
'no-restricted-syntax': 'off', // В for...of циклах ничего плохого нет
'spaced-comment': ['error', 'always', { markers: ['/'] }], /// разрешаем ts-require directive
'comma-dangle': ['error', 'always-multiline'],
'arrow-parens': ['error', 'always'],

'space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
indent: 'off',
'max-len': [
'error',
120,
2,
{
ignoreUrls: true,
ignoreComments: false,
ignoreRegExpLiterals: true,
ignoreStrings: true,
ignoreTemplateLiterals: true,
},
],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'return' },
{ blankLine: 'always', prev: '*', next: 'if' },
],
'implicit-arrow-linebreak': 'off',
'no-plusplus': 'off',
'max-classes-per-file': 'off',
'operator-linebreak': 'off',
'object-curly-newline': 'off',
'class-methods-use-this': 'off',
'no-confusing-arrow': 'off',
'function-paren-newline': 'off',
'no-param-reassign': 'off',
'no-shadow': 'warn',
'consistent-return': 'off',

'@typescript-eslint/explicit-function-return-type': 'off',

'import/prefer-default-export': 'off', // @grape: https://humanwhocodes.com/blog/2019/01/stop-using-default-exports-javascript-module/
'import/order': [
'error',
{
groups: [['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'always',
},
],
'import/no-unresolved': 'off',
'import/extensions': 'off',
'import/no-extraneous-dependencies': ['off'],
'arrow-body-style': 'off',
'no-unused-expressions': 'off',
},
};
7 changes: 7 additions & 0 deletions packages/eslint-config-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"url": "git+https://github.com/salute-developers/grail.git"
},
"author": "Salute Frontend Team <[email protected]>",
"exports": {
".": {
"require": "./index.js",
"import": "./index.mjs"
},
"./flat": "./flat/index.mjs"
},
"main": "index.js",
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">=8",
Expand Down
21 changes: 20 additions & 1 deletion packages/eslint-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ npm i -D @salutejs/prettier-config @typescript-eslint/eslint-plugin@8 @typescrip

```json
{
"extends": ["all-other-configs", "@salutejs/eslint-config"]
"extends": ["all-other-configs", "@salutejs/eslint-config"]
}
```

## Flat config for eslint

Also, we added a [flat configuration for ESLint](https://eslint.org/docs/latest/use/configure/configuration-files)

### Usage

```mjs
// Other imports
import flatConfig from "@salutejs/eslint-config/flat"


/** @type {import('eslint').Linter.FlatConfig[]} */
export default [
...flatConfig,
//... Other settings
];

```
141 changes: 141 additions & 0 deletions packages/eslint-config/flat/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
'use strict';

import eslintConfigBase from '@salutejs/eslint-config-base';
import reactPlugin from 'eslint-plugin-react';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import reactPerfPlugin from 'eslint-plugin-react-perf';
import jsxA11yPlugin from 'eslint-plugin-jsx-a11y';
import saluteRulesPlugin from 'eslint-plugin-salute-rules';
import prettierPlugin from 'eslint-plugin-prettier';
import prettierConfig from '@salutejs/prettier-config';

/** @type {import("eslint").Linter.Config[]} */
export default [
eslintConfigBase[0],

{
plugins: {
react: reactPlugin,
},
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
...reactPlugin.configs.recommended.rules,
'react/prop-types': 'off',
'react/static-property-placement': 'off',
'react/state-in-constructor': 'off',
'react/jsx-filename-extension': ['error', { extensions: ['.tsx'] }],
'react/jsx-one-expression-per-line': 'off',
'react/jsx-indent': ['error', 4],
'react/jsx-indent-props': ['error', 4],
'react/display-name': 'error',
'react/jsx-no-leaked-render': 'off',
'react/jsx-props-no-spreading': 'off',
'react/destructuring-assignment': 'off',
'react/sort-comp': 'off',
'react/no-array-index-key': 'off',
'react/require-default-props': 'off',
'react/function-component-definition': 'off',
'react/jsx-no-useless-fragment': 'off',
'react/no-unstable-nested-components': 'error',
},
settings: {
react: {
version: '18.3.1',
},
},
},

{
plugins: {
'react-hooks': reactHooksPlugin,
},
rules: {
...reactHooksPlugin.configs.recommended.rules,
},
},

{
plugins: {
'react-perf': reactPerfPlugin,
},
rules: {
...reactPerfPlugin.configs.recommended.rules,
},
},

{
plugins: {
'jsx-a11y': jsxA11yPlugin,
},
rules: {
...jsxA11yPlugin.configs.recommended.rules,
'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
},
},

{
plugins: {
'salute-rules': saluteRulesPlugin,
},
rules: {
...saluteRulesPlugin.configs.all.rules,
},
},

{
plugins: {
prettier: prettierPlugin,
},
rules: {
'prettier/prettier': ['error', prettierConfig],
},
},

{
files: ['**/*.ts', '**/*.tsx'],
rules: {
'no-restricted-imports': [
'error',
{
patterns: [
'@salutejs/plasma-ui/*',
'@salutejs/plasma-tokens/*',
'@salutejs/plasma-icons/*',
'@salutejs/plasma-web/*',
'@salutejs/plasma-b2c/*',
],
},
],
'default-param-last': 'warn',
'@typescript-eslint/member-ordering': [
'warn',
{
default: {
optionalityOrder: 'required-first',
},
},
],
},
},

{
files: ['**/*.tsx'],
languageOptions: {
globals: {
window: true,
document: true,
},
},
rules: {
'react/no-unknown-property': 'error',
},
},
];
Loading

0 comments on commit 70fddd4

Please sign in to comment.