Skip to content

Commit f017f5f

Browse files
committed
feat(lint): 添加qunar默认lint规则
1 parent 127206d commit f017f5f

File tree

4 files changed

+68
-30
lines changed

4 files changed

+68
-30
lines changed

lib/config/eslint.json

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"commonjs": true,
5-
"node": false
6-
},
7-
"extends": ["eslint:recommended"],
8-
"globals": [
9-
"$", "$$", "jQuery", "Promise"
10-
],
11-
"rules": {},
12-
"ignorePattern": ["/node_modules/*", "/bower_components/*", "/dev/*", "/prd/*"]
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"node": true
6+
},
7+
"globals": [
8+
"$",
9+
"$$",
10+
"jQuery",
11+
"Promise"
12+
],
13+
"rules": {
14+
"no-with": "error",
15+
"no-array-constructor": "error",
16+
"no-debugger": "error",
17+
"no-sequences": "error",
18+
"no-dupe-args": "error",
19+
"no-inner-declarations": "error",
20+
"no-unreachable": "error",
21+
"no-octal": "error",
22+
"no-dupe-keys": "error",
23+
"comma-dangle": ["error", "never"],
24+
"no-unused-vars": "error"
25+
},
26+
"ignorePattern": [
27+
"/fekit_modules/*",
28+
"/node_modules/*",
29+
"/bower_components/*",
30+
"/dev/*",
31+
"/prd/*"
32+
]
1333
}

lib/models/Project.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,23 +245,22 @@ var Project = function () {
245245
CLIEngine = requireg(sysPath.join(this.cwd, 'node_modules/', 'eslint')).CLIEngine;
246246
}
247247

248-
// prepare eslint config file
249-
// const configFilePath = sysPath.join(__dirname, '../../' ,'.eslintrc.json')
248+
// 优先使用本地配置
250249
var eslintExts = ['.js', '.yaml', '.yml', '.json', ''];
251250
var configFilePath = '';
252251
eslintExts.forEach(function (eslintExtItem) {
253252
if (_this3._fileExists(sysPath.join(_this3.cwd, '.eslintrc' + eslintExtItem))) {
254253
configFilePath = sysPath.join(_this3.cwd, '.eslintrc' + eslintExtItem);
254+
_this3.eslintConfig = requireg(configFilePath);
255255
}
256256
});
257257

258+
// 本地无lint配置,创建.eslintrc.json
258259
if (!configFilePath) {
259260
configFilePath = sysPath.join(this.cwd, '.eslintrc.json');
260261
fs.writeFileSync(configFilePath, JSON.stringify(this.eslintConfig, null, ' '));
261262
}
262263

263-
this.eslintConfig.configFile = configFilePath;
264-
265264
var cli = new CLIEngine(this.eslintConfig),
266265
report = cli.executeOnFiles(this._getLintFiles(dir, 'js')),
267266
formatter = cli.getFormatter();

src/config/eslint.json

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"commonjs": true,
5-
"node": false
6-
},
7-
"extends": ["eslint:recommended"],
8-
"globals": [
9-
"$", "$$", "jQuery", "Promise"
10-
],
11-
"rules": {},
12-
"ignorePattern": ["/node_modules/*", "/bower_components/*", "/dev/*", "/prd/*"]
2+
"env": {
3+
"browser": true,
4+
"commonjs": true,
5+
"node": true
6+
},
7+
"globals": [
8+
"$",
9+
"$$",
10+
"jQuery",
11+
"Promise"
12+
],
13+
"rules": {
14+
"no-with": "error",
15+
"no-array-constructor": "error",
16+
"no-debugger": "error",
17+
"no-sequences": "error",
18+
"no-dupe-args": "error",
19+
"no-inner-declarations": "error",
20+
"no-unreachable": "error",
21+
"no-octal": "error",
22+
"no-dupe-keys": "error",
23+
"comma-dangle": ["error", "never"],
24+
"no-unused-vars": "error"
25+
},
26+
"ignorePattern": [
27+
"/fekit_modules/*",
28+
"/node_modules/*",
29+
"/bower_components/*",
30+
"/dev/*",
31+
"/prd/*"
32+
]
1333
}

src/models/Project.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,17 @@ class Project {
216216
CLIEngine = requireg(sysPath.join(this.cwd, 'node_modules/', 'eslint')).CLIEngine
217217
}
218218

219-
// prepare eslint config file
220-
// const configFilePath = sysPath.join(__dirname, '../../' ,'.eslintrc.json')
219+
// 优先使用本地配置
221220
const eslintExts = ['.js', '.yaml', '.yml', '.json', '']
222221
let configFilePath = ''
223222
eslintExts.forEach((eslintExtItem) => {
224223
if(this._fileExists(sysPath.join(this.cwd, '.eslintrc' + eslintExtItem))) {
225224
configFilePath = sysPath.join(this.cwd, '.eslintrc' + eslintExtItem)
225+
this.eslintConfig = requireg(configFilePath)
226226
}
227227
})
228228

229+
// 本地无lint配置,创建.eslintrc.json
229230
if(!configFilePath) {
230231
configFilePath = sysPath.join(this.cwd, '.eslintrc.json')
231232
fs.writeFileSync(
@@ -234,8 +235,6 @@ class Project {
234235
);
235236
}
236237

237-
this.eslintConfig.configFile = configFilePath
238-
239238
const cli = new CLIEngine(this.eslintConfig),
240239
report = cli.executeOnFiles(this._getLintFiles(dir, 'js')),
241240
formatter = cli.getFormatter();

0 commit comments

Comments
 (0)