Skip to content

Commit 82ebf82

Browse files
authored
feat: add kintone-customize presets for flat config (#845)
1 parent 938e12b commit 82ebf82

15 files changed

+157
-50
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,22 @@ module.exports = [
9999
## Support rule set
100100

101101
- `@cybozu`
102+
- or `@cybozu/eslint-config/flat/presets/base` for Flat Config
102103
- This is included in the all following presets
103104
- `@cybozu/eslint-config/presets/node`
105+
- or `@cybozu/eslint-config/flat/presets/node` for Flat Config
104106
- Including `eslint-plugin-n`
105107
- `@cybozu/eslint-config/presets/typescript`
108+
- or `@cybozu/eslint-config/flat/presets/typescript` for Flat Config
106109
- Including `@typescript-eslint/eslint-plugin`
107110
- `@cybozu/eslint-config/presets/react`
111+
- or `@cybozu/eslint-config/flat/presets/react` for Flat Config
108112
- Including `eslint-plugin-react`, `eslint-plugin-jsx-ally` and `eslint-plugin-react-hooks`
109113
- `@cybozu/eslint-config/presets/react-typescript`
114+
- or `@cybozu/eslint-config/flat/presets/react-typescript` for Flat Config
110115
- Including `@cybozu/eslint-config/presets/typescript` and `@cybozu/eslint-config/presets/react`
111116
- `@cybozu/eslint-config/presets/es5`
117+
- or `@cybozu/eslint-config/flat/presets/es5` for Flat Config
112118

113119
## Prettier Support
114120

@@ -164,10 +170,14 @@ module.exports = {
164170
### Presets
165171

166172
- `@cybozu/eslint-config/preset/kintone-customize`
173+
- or `@cybozu/eslint-config/flat/presets/kintone-customize` for Flat Config
167174
- Preset for kintone customize/plugin-in development
168175
- `@cybozu/eslint-config/preset/kintone-customize-prettier`
176+
- or `@cybozu/eslint-config/flat/presets/kintone-customize-prettier` for Flat Config
169177
- Preset for kintone customize/plugin-in development including `prettier` config
170178
- `@cybozu/eslint-config/preset/kintone-customize-es5`
179+
- or `@cybozu/eslint-config/flat/presets/kintone-customize-es5` for Flat Config
171180
- Preset for kintone customize/plugin-in development in ES5
172181
- `@cybozu/eslint-config/preset/kintone-customize-es5-prettier`
182+
- or `@cybozu/eslint-config/flat/presets/kintone-customize-es5-prettier` for Flat Config
173183
- Preset for kintone customize/plugin-in development in ES5 including `prettier` config

flat/lib/base.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,28 @@ const importPlugin = require("eslint-plugin-import-x");
33
const eslint = require("@eslint/js");
44

55
/**
6+
* @param {{ overrideGlobals?: import("eslint").ESLint.Globals} | undefined} overrides
67
* @return { import("eslint").Linter.FlatConfig[] }
78
*/
8-
module.exports = function base() {
9+
module.exports = function base(overrides) {
910
return [
10-
eslint.configs.recommended,
1111
{
12-
plugins: {
13-
"import-x": importPlugin,
14-
},
1512
languageOptions: {
1613
ecmaVersion: "latest",
1714
sourceType: "module",
18-
globals: {
19-
...globals.browser,
20-
...globals.es2015,
21-
...globals.commonjs,
22-
},
15+
globals: overrides?.overrideGlobals
16+
? overrides.overrideGlobals
17+
: {
18+
...globals.browser,
19+
...globals.es2024,
20+
...globals.commonjs,
21+
},
22+
},
23+
},
24+
eslint.configs.recommended,
25+
{
26+
plugins: {
27+
"import-x": importPlugin,
2328
},
2429
rules: {
2530
// =======

flat/lib/es5.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const base = require("./base");
22
const globals = require("globals");
33
const eslint = require("@eslint/js");
44

5-
const baseRules = base()[1].rules;
5+
const baseRules = base()[2].rules;
66

77
// This rule can be parsed with ES5
88
delete baseRules["import-x/no-duplicates"];

flat/lib/kintone-es5.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const globals = require("globals");
2+
const kintoneGlobals = require("../globals/kintone");
3+
4+
/**
5+
* @return { import("eslint").Linter.FlatConfig[] }
6+
*/
7+
module.exports = function kintoneEs5() {
8+
return [
9+
{
10+
languageOptions: {
11+
ecmaVersion: 5,
12+
sourceType: "script",
13+
globals: {
14+
...globals.browser,
15+
...kintoneGlobals,
16+
},
17+
},
18+
rules: {
19+
strict: ["error", "function"],
20+
},
21+
},
22+
];
23+
};

flat/lib/kintone.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
const globals = require("globals");
22
const kintoneGlobals = require("../globals/kintone");
3+
const base = require("../lib/base.js");
34

45
/**
56
* @return { import("eslint").Linter.FlatConfig[] }
67
*/
78
module.exports = function kintone() {
8-
return [
9-
{
10-
languageOptions: {
11-
ecmaVersion: 5,
12-
sourceType: "script",
13-
globals: {
14-
...globals.browser,
15-
...kintoneGlobals,
16-
},
17-
},
18-
rules: {
19-
strict: ["error", "function"],
20-
},
9+
return base({
10+
overrideGlobals: {
11+
...globals.browser,
12+
...globals.es2024,
13+
...kintoneGlobals,
2114
},
22-
];
15+
});
2316
};
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
const es5 = require("../lib/es5.js");
2-
const kintone = require("../lib/kintone.js");
3-
const prettier = require("../lib/prettier.js");
2+
const kintoneEs5 = require("../lib/kintone-es5.js");
43
const kintoneGlobals = require("../globals/kintone.js");
4+
const prettier = require("../lib/prettier.js");
55

66
/**
77
* @type { import("eslint").Linter.Config[] }
88
*/
99
module.exports = [
1010
{ files: ["**/*.{js,cjs,mjs,jsx}"] },
11-
...es5(kintoneGlobals),
12-
...kintone(),
11+
...es5({ overrideGlobals: kintoneGlobals }),
12+
...kintoneEs5(),
1313
...prettier(),
1414
];

flat/presets/kintone-customize-es5.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
const es5 = require("../lib/es5.js");
2-
const kintone = require("../lib/kintone.js");
2+
const kintoneEs5 = require("../lib/kintone-es5.js");
33
const kintoneGlobals = require("../globals/kintone.js");
44

55
/**
66
* @type { import("eslint").Linter.Config[] }
77
*/
8-
module.exports = [...es5(kintoneGlobals), ...kintone()];
8+
module.exports = [
9+
{ files: ["**/*.{js,cjs,mjs,jsx}"] },
10+
...es5({ overrideGlobals: kintoneGlobals }),
11+
...kintoneEs5(),
12+
];
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const kintone = require("../lib/kintone.js");
2+
const prettier = require("../lib/prettier.js");
3+
4+
/**
5+
* @type { import("eslint").Linter.Config[] }
6+
*/
7+
module.exports = [
8+
{ files: ["**/*.{js,cjs,mjs,ts,mts,cts,jsx,tsx}"] },
9+
...kintone(),
10+
...prettier(),
11+
];

flat/presets/kintone-customize.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const kintone = require("../lib/kintone.js");
2+
3+
/**
4+
* @type { import("eslint").Linter.Config[] }
5+
*/
6+
module.exports = [
7+
{ files: ["**/*.{js,cjs,mjs,ts,mts,cts,jsx,tsx}"] },
8+
...kintone(),
9+
];

test/fixtures/base/ok.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Globals defined by jQuery
2-
/* global $, jQuery */
3-
41
const foos = [''];
52
foos.map((foo) => foo + foo);
63

@@ -10,6 +7,3 @@ async function hoge() {
107
return {...result};
118
}
129
hoge();
13-
14-
$.Deferred();
15-
jQuery.Deferred();

test/flat/kintone-es5-test.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const assert = require("assert");
2+
const kintoneEs5 = require("../../flat/lib/kintone-es5");
3+
const runLintWithFixturesFlat = require("../lib/runLintWithFixturesFlat");
4+
5+
describe("flat kintone-es5", () => {
6+
it("should get expected errors and warnings with kintone-es5 config", async () => {
7+
const result = await runLintWithFixturesFlat("kintone", kintoneEs5());
8+
assert.deepStrictEqual(result, {
9+
"error.js": {
10+
errors: ["strict", "strict"],
11+
},
12+
"ok.js": {},
13+
});
14+
});
15+
it("should be able to use kintone-customize-es5 as well as lib/kintone-es5", async () => {
16+
assert.deepStrictEqual(
17+
await runLintWithFixturesFlat("globals-kintone", kintoneEs5()),
18+
{
19+
"ok.js": {},
20+
"error.js": {
21+
errors: ["no-undef"],
22+
},
23+
}
24+
);
25+
});
26+
});

test/flat/kintone-test.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,16 @@ const kintone = require("../../flat/lib/kintone");
33
const runLintWithFixturesFlat = require("../lib/runLintWithFixturesFlat");
44

55
describe("flat kintone", () => {
6-
it("should get expected errors and warnings with kintone config", async () => {
7-
const result = await runLintWithFixturesFlat("kintone", kintone());
8-
assert.deepStrictEqual(result, {
9-
"error.js": {
10-
errors: ["strict", "strict"],
11-
},
12-
"ok.js": {},
13-
});
14-
});
15-
it("should be able to use kintone-customize-es5 as well as lib/kintone", async () => {
6+
it("should be able to use kintone-customize as well as lib/kintone", async () => {
167
assert.deepStrictEqual(
178
await runLintWithFixturesFlat("globals-kintone", kintone()),
189
{
19-
"ok.js": {},
10+
"ok.js": { warnings: ["spaced-comment"] },
2011
"error.js": {
2112
errors: ["no-undef"],
13+
warnings: ["spaced-comment"],
2214
},
23-
},
15+
}
2416
);
2517
});
2618
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const assert = require("assert");
2+
const kintoneCustomizePrettier = require("../../flat/presets/kintone-customize-prettier");
3+
const prettier = require("../../flat/presets/prettier");
4+
const runLintWithFixturesFlat = require("../lib/runLintWithFixturesFlat");
5+
6+
describe("flat preset kintone-customize-prettier", () => {
7+
it("should be able to use kintone-customize as well as preset/prettier", async () => {
8+
assert.deepStrictEqual(
9+
await runLintWithFixturesFlat("prettier", prettier),
10+
await runLintWithFixturesFlat("prettier", kintoneCustomizePrettier)
11+
);
12+
});
13+
});
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const assert = require("assert");
2+
const kintoneCustomize = require("../../flat/presets/kintone-customize");
3+
const base = require("../../flat/presets/base");
4+
const runLintWithFixturesFlat = require("../lib/runLintWithFixturesFlat");
5+
6+
describe("flat preset kintone-customize", () => {
7+
it("should be able to use kintone-customize as well as preset/base", async () => {
8+
assert.deepStrictEqual(
9+
await runLintWithFixturesFlat("base", base),
10+
await runLintWithFixturesFlat("base", kintoneCustomize)
11+
);
12+
});
13+
it("should get expected errors and warninigs with kintone globals", async () => {
14+
const result = await runLintWithFixturesFlat(
15+
"globals-kintone",
16+
kintoneCustomize
17+
);
18+
assert.deepStrictEqual(result, {
19+
"error.js": {
20+
errors: ["no-undef"],
21+
warnings: ["spaced-comment"],
22+
},
23+
"ok.js": {
24+
warnings: ["spaced-comment"],
25+
},
26+
});
27+
});
28+
});

test/lib/runLintWithFixturesFlat.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const runLintWithFixturesFlat = async (type, configObject) => {
1717
});
1818
const targetDir = path.resolve(__dirname, "..", "fixtures", type);
1919
const lintResult = await eslint.lintFiles([targetDir]);
20-
// console.log(JSON.stringify(lintResult, null, 2));
2120
return lintResult.reduce((results, { filePath, messages }) => {
2221
// strip path
2322
const fileName = filePath.replace(`${targetDir}/`, "");

0 commit comments

Comments
 (0)