Skip to content

Commit

Permalink
added new flat config for salutejs eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
pamellix committed Dec 24, 2024
1 parent 1270818 commit 8707e62
Show file tree
Hide file tree
Showing 8 changed files with 5,501 additions and 3,338 deletions.
8,557 changes: 5,220 additions & 3,337 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
"@auto-it/npm": "11.2.1",
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"@typescript-eslint/eslint-plugin": "8.18.1",
"@typescript-eslint/parser": "8.18.1",
"auto": "11.2.1",
"eslint": "8.57.1",
"eslint-plugin-import": "2.31.0",
"eslint-plugin-jsx-a11y": "6.10.2",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "7.37.2",
"eslint-plugin-react-hooks": "5.1.0",
"eslint-plugin-react-perf": "3.3.3",
"eslint-plugin-salute-rules": "1.0.0",
"lerna": "8.1.8",
"prettier": "3.3.3",
"prettier-plugin-packagejson": "2.5.2"
Expand Down
86 changes: 86 additions & 0 deletions packages/eslint-config-base/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"use strict"

import eslintRecommended from 'eslint/conf/eslint-recommended';
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.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',
},
},
];
4 changes: 4 additions & 0 deletions packages/eslint-config-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
},
"author": "Salute Frontend Team <[email protected]>",
"main": "index.js",
"exports": {
".": "./index.js",
"./flat": "./index.mjs"
},
"peerDependencies": {
"@typescript-eslint/eslint-plugin": ">=8",
"@typescript-eslint/parser": ">=8",
Expand Down
79 changes: 79 additions & 0 deletions packages/eslint-config-base/src/configs/eslint-all.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"use strict";

module.exports = [
{
files: ["**/*.ts", "**/*.tsx"],
languageOptions: {
parser: require("@typescript-eslint/parser"),
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
},
plugins: {
"@typescript-eslint": require("@typescript-eslint/eslint-plugin"),
import: require("eslint-plugin-import"),
},
rules: {
"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",
},
],
"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" },
],
"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",
"arrow-body-style": "off",
"no-unused-expressions": "off",

"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/explicit-function-return-type": "off",

"import/prefer-default-export": "off",
"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"],
},
},
];
11 changes: 11 additions & 0 deletions packages/eslint-config-base/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { version } = require("../package.json")

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

module.exports = [{
configs: {
all: require("./configs/eslint-all")
}
}]
90 changes: 90 additions & 0 deletions packages/eslint-config/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"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,
reactPlugin.configs.recommended,
reactHooksPlugin.configs.recommended,
reactPerfPlugin.configs.recommended,
jsxA11yPlugin.configs.recommended,
saluteRulesPlugin.configs.all,
prettierPlugin.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',

'jsx-a11y/no-static-element-interactions': 'off',
'jsx-a11y/click-events-have-key-events': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',

'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',
},
},
],
'prettier/prettier': ['error', prettierConfig],
},
overrides: [
{
files: ['*.tsx?'],
languageOptions: {
globals: {
window: true,
document: true,
},
},
rules: {
'react/no-unknown-property': 'error',
},
},
],
settings: {
react: {
version: '18.3.1',
},
},
},
];
2 changes: 1 addition & 1 deletion packages/eslint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "index.js",
"exports": {
".": "./index.js",
"./flat": "./src/index.js"
"./flat": "./index.mjs"
},
"scripts": {
"test": "jest"
Expand Down

0 comments on commit 8707e62

Please sign in to comment.