Skip to content

Commit 3c6c3ce

Browse files
authored
feat: add cybozu/eslint-config/presets/node and presets/node-prettier (#44)
1 parent 0c88a41 commit 3c6c3ce

File tree

10 files changed

+106
-22
lines changed

10 files changed

+106
-22
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ module.exports = {
8383
};
8484
```
8585

86+
### `@cybozu/eslint-config/node`
87+
88+
This rule set is for projects running on a Node environment.
89+
90+
```js
91+
module.exports = {
92+
extends: "@cybozu/eslint-config/presets/node"
93+
};
94+
```
95+
8696
### [Experimental] `@cybozu/eslint-config/presets/react`
8797

8898
This rule set is for projects using React, which has JSX support and rules related React provided by `eslint-plugin-react` and `eslint-plugin-jsx-ally`.
@@ -147,6 +157,7 @@ In order to this, you have to install `prettier` and choose a preset from the fo
147157
```
148158

149159
- `@cybozu/eslint-config/presets/prettier`
160+
- `@cybozu/eslint-config/presets/node-prettier`
150161
- `@cybozu/eslint-config/presets/react-prettier`
151162
- `@cybozu/eslint-config/presets/react-flowtype-prettier`
152163
- `@cybozu/eslint-config/presets/es5-prettier`

lib/node.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
extends: ["plugin:node/recommended"],
3+
rules: {
4+
"no-console": "off"
5+
}
6+
};

package-lock.json

Lines changed: 28 additions & 9 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
@@ -28,6 +28,7 @@
2828
"license": "MIT",
2929
"devDependencies": {
3030
"eslint": "^5.6.0",
31+
"eslint-plugin-node": "^7.0.1",
3132
"mocha": "^5.2.0",
3233
"npm-run-all": "^4.1.3",
3334
"prettier": "^1.14.3",

presets/node-prettier.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["../lib/base.js", "../lib/node.js", "../lib/prettier.js"]
3+
};

presets/node.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ["../lib/base.js", "../lib/node.js"]
3+
};

test/fixtures/node/error.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require('./unknown');
2+
3+
(async () => {
4+
await new Promise(r => r);
5+
})();

test/fixtures/node/ok.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const path = require('path');
2+
3+
console.log(path.resolve(__dirname));

test/node-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const assert = require("assert");
2+
const runLintWithFixtures = require("./lib/runLintWithFixtures");
3+
4+
describe("node", () => {
5+
it("should get expected errors and warninigs with node config", () => {
6+
const result = runLintWithFixtures("node");
7+
assert.deepStrictEqual(result, {
8+
"error.js": {
9+
errors: [
10+
"node/no-missing-require",
11+
"node/no-unsupported-features/es-syntax"
12+
]
13+
},
14+
"ok.js": {}
15+
});
16+
});
17+
});

test/presets-test.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@ describe("presets", () => {
4545
);
4646
});
4747
});
48+
describe("node", () => {
49+
it("should be able to use node as well as lib/node", () => {
50+
assert.deepStrictEqual(
51+
runLintWithFixtures("node"),
52+
runLintWithFixtures("node", "presets/node.js")
53+
);
54+
});
55+
});
56+
describe("kintone-customize-es5", () => {
57+
it("should be able to use kintone-customize-es5 as well as lib/es5 and lib/kintone", () => {
58+
assert.deepStrictEqual(
59+
runLintWithFixtures("es5"),
60+
runLintWithFixtures("es5", "presets/kintone-customize-es5.js")
61+
);
62+
});
63+
it("should be able to use kintone-customize-es5 as well as lib/kintone", () => {
64+
assert.deepStrictEqual(
65+
runLintWithFixtures("kintone", "presets/kintone-customize-es5.js"),
66+
{
67+
"ok.js": {},
68+
"error.js": { errors: ["strict", "strict"] }
69+
}
70+
);
71+
});
72+
});
4873
describe("prettier", () => {
4974
it("should be able to use prettier as well as lib/prettier", () => {
5075
assert.deepStrictEqual(
@@ -69,20 +94,11 @@ describe("presets", () => {
6994
);
7095
});
7196
});
72-
describe("kintone-customize-es5", () => {
73-
it("should be able to use kintone-customize-es5 as well as lib/es5 and lib/kintone", () => {
97+
describe("node-prettier", () => {
98+
it("should be able to use node-prettier as well as lib/prettier", () => {
7499
assert.deepStrictEqual(
75-
runLintWithFixtures("es5"),
76-
runLintWithFixtures("es5", "presets/kintone-customize-es5.js")
77-
);
78-
});
79-
it("should be able to use kintone-customize-es5 as well as lib/kintone", () => {
80-
assert.deepStrictEqual(
81-
runLintWithFixtures("kintone", "presets/kintone-customize-es5.js"),
82-
{
83-
"ok.js": {},
84-
"error.js": { errors: ["strict", "strict"] }
85-
}
100+
runLintWithFixtures("prettier"),
101+
runLintWithFixtures("prettier", "presets/node-prettier.js")
86102
);
87103
});
88104
});

0 commit comments

Comments
 (0)