This repository has been archived by the owner on Mar 3, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19302 from atom/use-eslint-for-linting
Use eslint + prettier for linting
- Loading branch information
Showing
12 changed files
with
973 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
spec/fixtures/**/*.js | ||
node_modules | ||
/vendor/ | ||
/out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,51 @@ | ||
{ | ||
"extends": "./script/node_modules/eslint-config-standard/eslintrc.json" | ||
} | ||
"extends": [ | ||
"./script/node_modules/eslint-config-standard/eslintrc.json", | ||
"./script/node_modules/eslint-config-prettier/index.js", | ||
"./script/node_modules/eslint-config-prettier/standard.js" | ||
], | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"parser": "babel-eslint", | ||
"parserOptions": { | ||
"ecmaVersion": 8, | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"globals": { | ||
"atom": true, | ||
"snapshotResult": true | ||
}, | ||
"rules": { | ||
"standard/no-callback-literal": ["off"], | ||
"no-mixed-operators": ["off"], | ||
"no-useless-escape": ["off"], | ||
"no-return-await": ["off"], | ||
"node/no-deprecated-api": ["off"], | ||
"prefer-promise-reject-errors": ["off"], | ||
"no-unused-expressions": ["off"], | ||
"symbol-description": ["off"], | ||
"no-use-before-define": ["off"], | ||
"prettier/prettier": ["off"] // disable prettier rules for now. | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": ["spec/**", "**-spec.js", "**.test.js"], | ||
"env": { | ||
"jasmine": true | ||
}, | ||
"globals": { | ||
"advanceClock": true, | ||
"fakeClearInterval": true, | ||
"fakeSetInterval": true, | ||
"waitsForPromise": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
*.swp | ||
*~ | ||
.DS_Store | ||
.eslintcache | ||
Thumbs.db | ||
.project | ||
.svn | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,60 @@ | ||
'use strict' | ||
|
||
const expandGlobPaths = require('./expand-glob-paths') | ||
const standard = require('standard') | ||
const path = require('path') | ||
const {spawn} = require('child_process') | ||
const process = require('process') | ||
|
||
const CONFIG = require('../config') | ||
|
||
module.exports = async function () { | ||
const globPathsToLint = [ | ||
path.join(CONFIG.repositoryRootPath, 'exports', '**', '*.js'), | ||
path.join(CONFIG.repositoryRootPath, 'packages', '**', '*.js'), | ||
path.join(CONFIG.repositoryRootPath, 'script', '**', '*.js'), | ||
path.join(CONFIG.repositoryRootPath, 'spec', '**', '*.js'), | ||
path.join(CONFIG.repositoryRootPath, 'src', '**', '*.js'), | ||
path.join(CONFIG.repositoryRootPath, 'static', '*.js') | ||
] | ||
const globPathsToIgnore = [ | ||
path.join(CONFIG.repositoryRootPath, 'spec', 'fixtures', '**', '*.js') | ||
] | ||
|
||
const [includePaths, excludePaths] = await Promise.all([ | ||
expandGlobPaths(globPathsToLint), | ||
expandGlobPaths(globPathsToIgnore) | ||
]) | ||
|
||
const paths = includePaths.filter( | ||
myPath => !excludePaths.includes(myPath) | ||
) | ||
|
||
return new Promise((resolve, reject) => { | ||
standard.lintFiles(paths, (error, lintOutput) => { | ||
if (error) { | ||
reject(error) | ||
} else { | ||
const errors = [] | ||
for (let result of lintOutput.results) { | ||
for (let message of result.messages) { | ||
errors.push({ | ||
path: result.filePath, | ||
lineNumber: message.line, | ||
message: message.message, | ||
rule: message.ruleId | ||
}) | ||
} | ||
const eslintArgs = ['--cache', '--format', 'json'] | ||
|
||
if (process.argv.includes('--fix')) { | ||
eslintArgs.push('--fix') | ||
} | ||
|
||
const eslintBinary = process.platform === 'win32' ? 'eslint.cmd' : 'eslint' | ||
const eslint = spawn( | ||
path.join('script', 'node_modules', '.bin', eslintBinary), | ||
[...eslintArgs, '.'], | ||
{ cwd: CONFIG.repositoryRootPath } | ||
) | ||
|
||
let output = '' | ||
let errorOutput = '' | ||
eslint.stdout.on('data', data => { | ||
output += data.toString() | ||
}) | ||
|
||
eslint.stderr.on('data', data => { | ||
errorOutput += data.toString() | ||
}) | ||
|
||
eslint.on('error', error => reject(error)) | ||
eslint.on('close', exitCode => { | ||
const errors = [] | ||
let files | ||
|
||
try { | ||
files = JSON.parse(output) | ||
} catch (_) { | ||
reject(errorOutput) | ||
return | ||
} | ||
|
||
for (const file of files) { | ||
for (const error of file.messages) { | ||
errors.push({ | ||
path: file.filePath, | ||
message: error.message, | ||
lineNumber: error.line, | ||
rule: error.ruleId | ||
}) | ||
} | ||
resolve(errors) | ||
} | ||
|
||
resolve(errors) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.