-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy patheslint.config.mjs
189 lines (187 loc) · 4.77 KB
/
eslint.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import pixRecommendedConfig from "@1024pix/eslint-plugin/config";
import babelParser from "@babel/eslint-parser";
import { fixupPluginRules } from "@eslint/compat";
import chai from "eslint-plugin-chai-expect";
import i18nJsonPlugin from "eslint-plugin-i18n-json";
import _import from "eslint-plugin-import-x";
import knex from "eslint-plugin-knex";
import mocha from "eslint-plugin-mocha";
import nRecommendedConfig from "eslint-plugin-n";
import prettierRecommendedConfig from "eslint-plugin-prettier/recommended";
import unicorn from "eslint-plugin-unicorn";
const nonPhraseGeneratedFiles = [
"translations/en.json",
"translations/fr.json",
];
export default [
...pixRecommendedConfig,
prettierRecommendedConfig,
nRecommendedConfig.configs["flat/recommended"],
{ plugins: { "chai-expect": fixupPluginRules(chai) } },
{ plugins: { import: _import } },
{ plugins: { knex: fixupPluginRules(knex) } },
{ plugins: { unicorn } },
{
files: ["**/eslint.config.mjs"],
languageOptions: {
sourceType: "module",
},
rules: {
"n/no-unpublished-import": "off",
},
},
{
files: ["**/*.cjs"],
languageOptions: {
globals: { module: "readonly", require: "readonly" },
},
},
{
files: ["**/*.js"],
languageOptions: {
parser: babelParser,
parserOptions: {
ecmaVersion: 2020,
sourceType: "module",
requireConfigFile: false,
babelOptions: {
configFile: false,
babelrc: false,
parserOpts: {
plugins: ["importAttributes"],
},
},
},
},
rules: {
"no-console": "error",
"no-sync": "error",
"knex/avoid-injections": "error",
"no-empty-function": "error",
"n/no-process-exit": "error",
"unicorn/no-empty-file": "error",
"unicorn/prefer-node-protocol": "error",
"n/no-unpublished-import": "off",
"import/no-restricted-paths": [
"error",
{
zones: [
{
target: ["api/lib/domain/usecases", "lib/domain/usecases"],
from: [
"api/lib/infrastructure/repositories",
"lib/infrastructure/repositories",
],
except: [],
message:
"Repositories are automatically injected in use-case, you don't need to import them. Check for further details: https://github.com/1024pix/pix/blob/dev/docs/adr/0046-injecter-les-dependances-api.md",
},
{ target: "tests/unit", from: "db" },
],
},
],
},
},
{
...mocha.configs.flat.recommended,
files: ["tests/**/*.js"],
rules: {
...mocha.configs.flat.recommended.rules,
"mocha/no-hooks-for-single-case": "off",
"mocha/no-exclusive-tests": "error",
"mocha/no-pending-tests": "error",
"mocha/no-skipped-tests": "error",
"mocha/no-top-level-hooks": "error",
"mocha/no-setup-in-describe": ["error"],
},
},
{
files: ["tests/integration/**/*.js"],
rules: {
"no-restricted-modules": [
"error",
{
paths: ["@hapi/hapi"],
},
],
},
},
{
files: ["tests/integration/application/**/*.js"],
rules: {
"no-restricted-modules": [
"error",
{
paths: [
{
name: "../../../server",
message: "Please use http-server-test instead.",
},
{
name: "../../../../server",
message: "Please use http-server-test instead.",
},
],
},
],
},
},
{
files: ["tests/unit/**/*.js"],
rules: {
"no-restricted-imports": [
"error",
{
paths: ["knex", "pg"],
},
],
},
},
{
files: ["scripts/**/*.js"],
rules: {
"no-console": "off",
},
},
{
files: ["lib/**/*.js"],
rules: {
"no-restricted-modules": [
"error",
{
paths: [
{
name: "axios",
message: "Please use http-agent instead (ADR 23)",
},
],
},
],
"n/no-process-env": "error",
},
},
{
files: ["lib/application/**/*.js"],
rules: {
"no-restricted-syntax": [
"error",
{
selector: "CallExpression[callee.name='parseInt']",
message:
"parseInt is unnecessary here because Joi already casts string into number if the field is properly described (Joi.number())",
},
],
},
},
{
files: nonPhraseGeneratedFiles,
plugins: { "i18n-json": i18nJsonPlugin },
processor: {
meta: { name: ".json" },
...i18nJsonPlugin.processors[".json"],
},
rules: {
...i18nJsonPlugin.configs.recommended.rules,
},
},
];