Skip to content

Commit 939909b

Browse files
committed
feat: add presets/es5 and presets/es5-prettier
1 parent 040c43c commit 939909b

File tree

8 files changed

+101
-0
lines changed

8 files changed

+101
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ module.exports = {
118118
};
119119
```
120120

121+
### [Experimental] `@cybozu/eslint-config/presets/es5`
122+
123+
This rule set is for projects using ES5.
124+
125+
```js
126+
module.exports = {
127+
extends: "@cybozu/eslint-config/presets/es5"
128+
};
129+
```
130+
121131
## [Experimental] Prettier Support
122132

123133
Prettier is a code formatter, which supports not only JavaScript but also other languages.
@@ -139,5 +149,6 @@ In order to this, you have to install `prettier` and choose a preset from the fo
139149
- `@cybozu/eslint-config/presets/prettier`
140150
- `@cybozu/eslint-config/presets/react-prettier`
141151
- `@cybouz/eslint-config/presets/react-flowtype-prettier`
152+
- `@cybouz/eslint-config/presets/es5-prettier`
142153

143154
**Currently, we don't support customized Prettier config**

lib/es5.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const base = require("./base");
2+
3+
const baseRules = base.rules;
4+
// This rule can be parsed with ES5
5+
delete baseRules["import/no-duplicates"];
6+
7+
module.exports = {
8+
extends: ["eslint:recommended"],
9+
parserOptions: {
10+
ecmaVersion: 5,
11+
sourceType: "script"
12+
},
13+
env: {
14+
browser: true,
15+
commonjs: true
16+
},
17+
rules: Object.assign({}, baseRules, {
18+
// Disable all rules about ES6
19+
"arrow-body-style": "off",
20+
"arrow-parens": "off",
21+
"arrow-spacing": "off",
22+
"constructor-super": "off",
23+
"generator-star-spacing": "off",
24+
"no-class-assign": "off",
25+
"no-confusing-arrow": "off",
26+
"no-const-assign": "off",
27+
"no-dupe-class-members": "off",
28+
"no-duplicate-imports": "off",
29+
"no-new-symbol": "off",
30+
"no-restricted-imports": "off",
31+
"no-this-before-super": "off",
32+
"no-useless-computed-key": "off",
33+
"no-useless-constructor": "off",
34+
"no-useless-rename": "off",
35+
"no-var": "off",
36+
"object-shorthand": "off",
37+
"prefer-arrow-callback": "off",
38+
"prefer-const": "off",
39+
"prefer-destructuring": "off",
40+
"prefer-numeric-literals": "off",
41+
"prefer-reflect": "off",
42+
"prefer-rest-params": "off",
43+
"prefer-spread": "off",
44+
"prefer-template": "off",
45+
"require-yield": "off",
46+
"rest-spread-spacing": "off",
47+
"sort-imports": "off",
48+
"symbol-description": "off",
49+
"template-curly-spacing": "off",
50+
"yield-star-spacing": "off"
51+
})
52+
};

presets/es5-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/es5.js", "../lib/prettier.js"]
3+
};

presets/es5.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/es5.js"]
3+
};

test/es5-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("es5", () => {
5+
it("should get expected errors and warninigs with es5 config", () => {
6+
const result = runLintWithFixtures("es5");
7+
assert.deepStrictEqual(result, {
8+
"error.js": {
9+
errors: ["no-unused-vars", "no-redeclare"]
10+
},
11+
"warning.js": {
12+
warnings: ["array-callback-return"]
13+
},
14+
"ok.js": {}
15+
});
16+
});
17+
});

test/fixtures/es5/error.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
var obj = {};
2+
var obj = {};
3+

test/fixtures/es5/ok.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var foos = [''];
2+
foos.map(function(foo) {
3+
return foo + foo;
4+
});

test/fixtures/es5/warning.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var a = 1;
2+
var b = 2;
3+
4+
alert(a + b);
5+
6+
[].map(function(v) {
7+
alert(v);
8+
});

0 commit comments

Comments
 (0)