Skip to content

Commit 7de7ddf

Browse files
fix: better configuration for module/commonjs/dirty format (#51)
1 parent 90a979e commit 7de7ddf

File tree

18 files changed

+139
-7
lines changed

18 files changed

+139
-7
lines changed

configs.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { globalIgnores } from "eslint/config";
44
import semver from "semver";
55
import configs from "./configs/index.js";
66
import ignorePaths from "./ignore-paths.js";
7+
import { typescriptExtensions } from "./configs/utils/extensions.js";
78

89
const SKIP_TIME = 5000;
910

@@ -249,7 +250,15 @@ function getTypescriptConfig() {
249250

250251
return [
251252
configs["typescript/recommended"],
252-
isStrict ? { rules: { strict: "off" } } : {},
253+
isStrict
254+
? {
255+
files: [
256+
`**/*.{${typescriptExtensions.map((item) => item.slice(1)).join(",")}}`,
257+
],
258+
ignores: ["**/*.d.ts"],
259+
rules: { strict: "off" },
260+
}
261+
: {},
253262
];
254263
}
255264

configs/node.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,12 @@ async function getCommonJSConfig() {
149149
"n/no-path-concat": "error",
150150
"import/extensions": [
151151
"error",
152-
"never",
152+
"always",
153153
{
154154
ignorePackages: true,
155+
checkTypeImports: true,
155156
pattern: {
156-
ts: "always",
157-
cts: "always",
158-
mts: "always",
159-
tsx: "always",
157+
js: "never",
160158
},
161159
},
162160
],

eslint.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
import { defineConfig } from "eslint/config";
22
import config from "../eslint-config-webpack/index.js";
3+
import configs from "../eslint-config-webpack/configs.js";
34

45
export default defineConfig([
56
{
7+
ignores: [
8+
"./validation/commonjs-package/**/*",
9+
"./validation/module-package/**/*",
10+
"./validation/dirty-package/**/*",
11+
],
612
extends: [config],
713
},
14+
// For test purposes
15+
{
16+
files: ["./validation/commonjs-package/**/*"],
17+
extends: [configs["recommended-commonjs"]],
18+
},
19+
{
20+
files: ["./validation/module-package/**/*"],
21+
extends: [configs["recommended-module"]],
22+
},
23+
{
24+
files: ["./validation/dirty-package/**/*"],
25+
extends: [configs["recommended-dirty"]],
26+
},
827
]);

validation/code.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const myOtherCode = require("./module.js");
66
const otherSum = require("./module");
77

88
// eslint-disable-next-line import/no-unresolved
9-
require("./unknown");
9+
require("./unknown.unknown");
1010

1111
require("./style.css");
1212

validation/commonjs-package/file.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"use strict";
2+
3+
const mod = require("./my-module");
4+
const otherMod = require("./other-module.cjs");
5+
// eslint-disable-next-line import/extensions
6+
const modAgain = require("./my-module.js");
7+
8+
const foo = 1;
9+
const bar = 2;
10+
11+
/**
12+
* @param {number} a a
13+
* @param {number} b b
14+
* @returns {number} sum
15+
*/
16+
function sum(a, b) {
17+
return a + b;
18+
}
19+
20+
sum(foo, bar);
21+
sum(mod.a, mod.b);
22+
sum(otherMod.a, otherMod.b);
23+
sum(modAgain.a, modAgain.b);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
module.exports.a = 1;
4+
module.exports.b = 2;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
module.exports.a = 1;
4+
module.exports.b = 2;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "commonjs-package",
3+
"description": "Test",
4+
"version": "1.0.0"
5+
}

validation/dirty-package/file.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { a, b } from "./my-module.js";
2+
import otherMod from "././other-module.cjs";
3+
4+
const commonJSModule = require("./module-js-common.js");
5+
6+
const foo = 1;
7+
const bar = 2;
8+
9+
/**
10+
* @param {number} a a
11+
* @param {number} b b
12+
* @returns {number} sum
13+
*/
14+
function sum(a, b) {
15+
return a + b;
16+
}
17+
18+
sum(foo, bar);
19+
sum(a, b);
20+
sum(otherMod.a, otherMod.b);
21+
sum(commonJSModule.a, commonJSModule.b);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = 100;

0 commit comments

Comments
 (0)