Skip to content

Commit 30f2f6c

Browse files
refactor: enable more rules (#32)
1 parent f3769fa commit 30f2f6c

File tree

9 files changed

+144
-55
lines changed

9 files changed

+144
-55
lines changed

configs/browser.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import globals from "globals";
2+
import importPlugin from "eslint-plugin-import";
23

34
const recommendedBrowserConfig = {
45
languageOptions: {
56
globals: {
67
...globals.browser,
78
},
89
},
10+
plugins: {
11+
import: importPlugin,
12+
},
13+
rules: {
14+
"import/extensions": ["error", "always", { ignorePackages: true }],
15+
},
916
};
1017

1118
export default {

configs/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import javascriptConfig from "./javascript.js";
33
import jestConfig from "./jest.js";
44
import markdownConfig from "./markdown.js";
55
import nodeConfig from "./node.js";
6-
import prettierConfig from "./prettier.js";
6+
import stylisticConfig from "./stylistic.js";
77
import typescriptConfig from "./typescript.js";
88

99
const configs = {
@@ -12,7 +12,7 @@ const configs = {
1212
...jestConfig,
1313
...markdownConfig,
1414
...nodeConfig,
15-
...prettierConfig,
15+
...stylisticConfig,
1616
...typescriptConfig,
1717
};
1818

configs/javascript.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ const suggestions = {
228228
// No need
229229
// "consistent-this": "error",
230230

231-
// No need here
231+
// Configuration in `stylistic`
232232
// curly: "off",
233233

234234
// No need
@@ -336,7 +336,6 @@ const suggestions = {
336336

337337
"no-alert": "error",
338338

339-
// No need
340339
"no-array-constructor": "error",
341340

342341
// No need
@@ -744,8 +743,7 @@ const unicornRules = {
744743
// No need
745744
// "unicorn/no-await-expression-member": "off",
746745

747-
// No need
748-
// "unicorn/no-await-in-promise-methods": "off",
746+
"unicorn/no-await-in-promise-methods": "error",
749747

750748
"unicorn/no-console-spaces": "error",
751749

@@ -1093,7 +1091,7 @@ const importRules = {
10931091
// No need
10941092
// "import/exports-last": "off",
10951093

1096-
// TODO
1094+
// Not here
10971095
// "import/extensions": ["error", "always", { ignorePackages: true }],
10981096

10991097
"import/first": "error",
@@ -1105,7 +1103,7 @@ const importRules = {
11051103
// "import/max-dependencies": "off",
11061104

11071105
// No need
1108-
// TODO
1106+
// We have `@stylistic/padding-line-between-statements`
11091107
// "import/newline-after-import": "off",
11101108

11111109
// No need

configs/node.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import globals from "globals";
22
import nodePlugin from "eslint-plugin-n";
3+
import importPlugin from "eslint-plugin-import";
34

45
const commonRules = {
56
// No need
@@ -8,8 +9,8 @@ const commonRules = {
89
// Depends on `sourceType` and enabled below only for commonjs
910
// "n/exports-style": "error",
1011

11-
// Depends on `sourceType` and enabled below only for module
12-
// "n/file-extension-in-import": "error",
12+
// We have the `import/extensions` rule
13+
"n/file-extension-in-import": "off",
1314

1415
// There is no need, as in some cases we want to load a module lazily.
1516
// "n/global-require": "error",
@@ -118,26 +119,36 @@ const commonRules = {
118119
const commonjs = {
119120
...nodePlugin.configs["flat/recommended-script"],
120121
name: "node/commonjs",
122+
plugins: {
123+
...nodePlugin.configs["flat/recommended-script"].plugins,
124+
import: importPlugin,
125+
},
121126
rules: {
122127
...commonRules,
123128
"n/exports-style": "error",
124129
"n/no-path-concat": "error",
130+
"import/extensions": ["error", "never", { ignorePackages: true }],
125131
},
126132
};
127133

128134
const module = {
129135
...nodePlugin.configs["flat/recommended-module"],
130136
name: "node/module",
137+
plugins: {
138+
...nodePlugin.configs["flat/recommended-script"].plugins,
139+
import: importPlugin,
140+
},
131141
rules: {
132142
...commonRules,
133-
"n/file-extension-in-import": "error",
143+
"import/extensions": ["error", "always", { ignorePackages: true }],
134144
},
135145
};
136146

137147
const dirty = {
138148
name: "node/dirty",
139149
plugins: {
140150
n: nodePlugin,
151+
import: importPlugin,
141152
},
142153
languageOptions: {
143154
sourceType: "module",
@@ -156,6 +167,8 @@ const dirty = {
156167
rules: {
157168
...commonjs.rules,
158169
...module.rules,
170+
// Disable for dirty modules
171+
"import/extensions": ["off"],
159172
},
160173
};
161174

configs/prettier.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

configs/stylistic.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import prettierPlugin from "eslint-plugin-prettier";
2+
import prettierConfig from "eslint-plugin-prettier/recommended";
3+
import stylisticPlugin from "@stylistic/eslint-plugin";
4+
5+
const recommendedConfig = {
6+
...prettierConfig,
7+
name: "stylistic/recommended",
8+
plugins: {
9+
"@stylistic": stylisticPlugin,
10+
prettier: prettierPlugin,
11+
},
12+
rules: {
13+
"prettier/prettier": "error",
14+
curly: ["error", "multi-line", "consistent"],
15+
"@stylistic/lines-between-class-members": "error",
16+
"@stylistic/quotes": [
17+
"error",
18+
"double",
19+
{ avoidEscape: true, allowTemplateLiterals: false },
20+
],
21+
"@stylistic/spaced-comment": [
22+
"error",
23+
"always",
24+
{
25+
line: {
26+
// Space here to support sprockets directives
27+
markers: ["=", "!"],
28+
exceptions: ["-", "+"],
29+
},
30+
block: {
31+
// Space here to support sprockets directives
32+
markers: ["=", "!"],
33+
exceptions: ["-", "+"],
34+
balanced: true,
35+
},
36+
},
37+
],
38+
"@stylistic/padding-line-between-statements": [
39+
"error",
40+
{ blankLine: "always", prev: ["cjs-export"], next: "*" },
41+
{ blankLine: "always", prev: "*", next: ["cjs-export"] },
42+
{
43+
blankLine: "any",
44+
prev: ["cjs-export"],
45+
next: ["cjs-export"],
46+
},
47+
// Require newline between blocks of `cjs-import` and any lines between `cjs-import`
48+
{ blankLine: "always", prev: ["cjs-import"], next: "*" },
49+
{ blankLine: "always", prev: "*", next: ["cjs-import"] },
50+
{
51+
blankLine: "any",
52+
prev: ["cjs-import"],
53+
next: ["cjs-import"],
54+
},
55+
// Require newline between blocks of `export` and any lines between `export`
56+
{ blankLine: "always", prev: ["export"], next: "*" },
57+
{ blankLine: "always", prev: "*", next: ["export"] },
58+
{
59+
blankLine: "any",
60+
prev: ["export"],
61+
next: ["export"],
62+
},
63+
// Require newline between blocks of `import` and any lines between `import`
64+
{ blankLine: "always", prev: ["import"], next: "*" },
65+
{ blankLine: "always", prev: "*", next: ["import"] },
66+
{
67+
blankLine: "any",
68+
prev: ["import"],
69+
next: ["import"],
70+
},
71+
],
72+
},
73+
};
74+
75+
export default {
76+
"stylistic/recommended": recommendedConfig,
77+
};

validation/code.cjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
"use strict";
22

33
const code = require("./module.cjs");
4+
// eslint-disable-next-line no-unused-vars, import/extensions
5+
const myOtherCode = require("./module.js");
46
const otherSum = require("./module");
57

68
// eslint-disable-next-line import/no-unresolved
79
require("./unknown");
810

911
require("./style.css");
1012

13+
const { aaa } = require("./module.cjs");
14+
15+
otherSum(aaa, 2);
16+
17+
const { bbb } = require("./module.cjs");
18+
19+
otherSum(bbb, 2);
20+
1121
code();
1222
otherSum(1, 2);
1323

validation/code.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { CLIEngine, linter } from "eslint";
22
import sumFn from "./module.js";
33
import * as names from "./named-exports.js";
4-
54
// eslint-disable-next-line import/named, no-duplicate-imports
65
import { notFoo } from "./module.js";
6+
// eslint-disable-next-line no-unused-vars, import/extensions, import/no-unresolved
7+
import { myVar } from "./without-extension";
78

89
import "./style.css";
910

@@ -939,3 +940,9 @@ export default function myFunctionDeclaration() {
939940
export const myArrayFunction = () => {
940941
// ...
941942
};
943+
944+
export const aaa = 1;
945+
946+
sumFn(1, 2);
947+
948+
export const bbb = 1;

validation/module.cjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
11
"use strict";
22

3+
/**
4+
* @returns {void}
5+
*/
6+
function test() {
7+
// Nothing
8+
}
9+
310
/**
411
* @returns {string} result
512
*/
613
module.exports = function test() {
714
return "test";
815
};
16+
17+
/**
18+
* @returns {string} result
19+
*/
20+
module.exports.other = function other() {
21+
return "test";
22+
};
23+
24+
module.exports.aaa = 1;
25+
26+
test();
27+
28+
module.exports.bbb = 1;

0 commit comments

Comments
 (0)