Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #19302 from atom/use-eslint-for-linting
Browse files Browse the repository at this point in the history
Use eslint + prettier for linting
  • Loading branch information
rafeca committed May 13, 2019
2 parents a489661 + 4048b49 commit fe95e05
Show file tree
Hide file tree
Showing 12 changed files with 973 additions and 571 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
@@ -0,0 +1,4 @@
spec/fixtures/**/*.js
node_modules
/vendor/
/out/
52 changes: 50 additions & 2 deletions .eslintrc.json
@@ -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
}
}
]
}
1 change: 1 addition & 0 deletions .gitignore
@@ -1,6 +1,7 @@
*.swp
*~
.DS_Store
.eslintcache
Thumbs.db
.project
.svn
Expand Down
4 changes: 4 additions & 0 deletions .prettierrc
@@ -0,0 +1,4 @@
{
"semi": false,
"singleQuote": true
}
3 changes: 2 additions & 1 deletion benchmarks/benchmark-runner.js
Expand Up @@ -38,7 +38,8 @@ module.exports = async ({test, benchmarkPaths}) => {
if (data.points.length > 1) {
const canvas = document.createElement('canvas')
benchmarkContainer.appendChild(canvas)
const chart = new Chart(canvas, {
// eslint-disable-next-line no-new
new Chart(canvas, {
type: 'line',
data: {
datasets: [{label: key, fill: false, data: data.points}]
Expand Down
6 changes: 3 additions & 3 deletions resources/win/atom.js
Expand Up @@ -2,8 +2,8 @@ var path = require('path');
var spawn = require('child_process').spawn;

var atomCommandPath = path.resolve(__dirname, '..', '..', 'atom.exe');
var arguments = process.argv.slice(2);
arguments.unshift('--executed-from', process.cwd());
var args = process.argv.slice(2);
args.unshift('--executed-from', process.cwd());
var options = {detached: true, stdio: 'ignore'};
spawn(atomCommandPath, arguments, options);
spawn(atomCommandPath, args, options);
process.exit(0);
85 changes: 47 additions & 38 deletions script/lib/lint-java-script-paths.js
@@ -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)
})
})
}

0 comments on commit fe95e05

Please sign in to comment.