Skip to content

Commit aad288c

Browse files
authored
Merge pull request #170 from ani-team/feature/strict-eslint
Restrict eslint ## CHANGELOG - (#157) Ограничение макс. кол-ва строк в функции (48) - (#157) Ограничение макс. длины в файлах (120) - (#157) Ограничение импортов (согласно fdd и запрету приватных импортов) - (#157) Добавлены некоторые базовые eslint и unicorn правила ![image](https://user-images.githubusercontent.com/42924400/100811042-cc047300-344a-11eb-8a4d-b391b6f9f5ba.png)
2 parents 3f2bc81 + 3cf9290 commit aad288c

File tree

13 files changed

+268
-30
lines changed

13 files changed

+268
-30
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ dist/**
33
build/**
44
*.gen.ts
55
.github
6+
public/
7+
.workflows

.eslintrc.js

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
/** Разрешенные импорты (с публичными API) */
2+
const ALLOWED_PATH_GROUPS = ["shared", "shared/**", "pages", "features", "models"].map(
3+
(pattern) => ({
4+
pattern,
5+
group: "internal",
6+
position: "after",
7+
}),
8+
);
9+
/** Для запрета приватных путей */
10+
const DENIED_PATH_GROUPS = ["app/**", "pages/**", "features/**", "shared/*/**"];
11+
112
module.exports = {
213
parser: "@typescript-eslint/parser",
314
parserOptions: {
@@ -12,7 +23,7 @@ module.exports = {
1223
browser: true,
1324
es6: true,
1425
},
15-
plugins: ["react", "@typescript-eslint", "@graphql-eslint"],
26+
plugins: ["react", "@typescript-eslint", "@graphql-eslint", "unicorn"],
1627
extends: [
1728
"react-app",
1829
"eslint:recommended",
@@ -25,29 +36,49 @@ module.exports = {
2536
"prettier/react",
2637
],
2738
rules: {
39+
// imports
2840
"import/first": 2,
2941
"import/no-unresolved": 0,
3042
"import/order": [
3143
2,
3244
{
33-
pathGroups: [
34-
"shared",
35-
"shared/**",
36-
"pages",
37-
"pages/**",
38-
"features",
39-
"features/**",
40-
"models",
41-
].map((pattern) => ({
42-
pattern,
43-
group: "internal",
44-
position: "after",
45-
})),
45+
pathGroups: ALLOWED_PATH_GROUPS,
4646
// TODO: Добавить сортировку `import "./index.scss";` (располагать внизу)
4747
pathGroupsExcludedImportTypes: ["builtin"],
4848
groups: ["builtin", "external", "internal", "parent", "sibling", "index"],
4949
},
5050
],
51+
// TODO: specify message: ("Please use allowed public API (not private imports!)")
52+
"no-restricted-imports": [1, { patterns: DENIED_PATH_GROUPS }],
53+
// variables
54+
"prefer-const": 2,
55+
"no-var": 2,
56+
// base
57+
"camelcase": [1, { ignoreDestructuring: true, ignoreImports: true, properties: "never" }],
58+
"no-else-return": 2,
59+
"max-len": [1, { code: 120 }],
60+
"dot-notation": 2,
61+
"eol-last": 2,
62+
// alert, console
63+
"no-alert": 2,
64+
"no-console": 0,
65+
// equals
66+
"eqeqeq": 1,
67+
"no-eq-null": 2,
68+
// function
69+
"max-params": [1, 2],
70+
"max-lines-per-function": [1, 48],
71+
"arrow-parens": [2, "always"],
72+
// plugin:unicorn
73+
"unicorn/no-for-loop": 2,
74+
"unicorn/no-abusive-eslint-disable": 2,
75+
"unicorn/no-array-instanceof": 2,
76+
"unicorn/no-zero-fractions": 2,
77+
"unicorn/prefer-includes": 2,
78+
"unicorn/prefer-text-content": 2,
79+
"unicorn/import-index": 2,
80+
"unicorn/throw-new-error": 2,
81+
// plugin:graphql
5182
"@graphql-eslint/no-anonymous-operations": 2,
5283
},
5384
overrides: [
@@ -57,6 +88,7 @@ module.exports = {
5788
plugins: ["@graphql-eslint"],
5889
rules: {
5990
"prettier/prettier": 0,
91+
"max-len": 0,
6092
},
6193
},
6294
],

package-lock.json

Lines changed: 194 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"eslint": "^7.11.0",
7878
"eslint-config-prettier": "^6.13.0",
7979
"eslint-plugin-prettier": "^3.1.4",
80+
"eslint-plugin-unicorn": "^23.0.0",
8081
"husky": "^4.3.0",
8182
"lint-staged": "^10.4.2",
8283
"prettier": "^2.1.2",

src/features/auth/page/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import React from "react";
22
import { GithubFilled } from "@ant-design/icons";
33
import { Alert, Card } from "antd";
44
import { alert } from "shared/helpers";
5-
// !!! FIXME: loop imports
5+
// !!! FIXME: это плохо( + loop imports
6+
// eslint-disable-next-line import/order
67
import { useTitle } from "pages/helpers";
78
import { authorizeGithub } from "../firebase";
89
import { useAuth } from "../hooks";

src/features/repo-details/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ const RepoDetails = ({ repo: identity }: Props) => {
2929
});
3030
const repository = data?.repository;
3131

32-
const languages = repository?.languages?.nodes?.filter(
33-
(lang): lang is Language => lang != null,
34-
);
32+
const languages = repository?.languages?.nodes?.filter((lang): lang is Language => !!lang);
3533
const collaborators = repository?.collaborators?.nodes?.filter(
36-
(collaborator): collaborator is Collaborator => collaborator != null,
34+
(collaborator): collaborator is Collaborator => !!collaborator,
3735
);
3836
return (
3937
<div className="flex flex-col">

0 commit comments

Comments
 (0)