Permalink
Browse files

๐Ÿ‘• Fix all eslint linting errors

  • Loading branch information...
1 parent 28a4a7d commit 589658e3152de16f8c2d933cd5b0bd4a3f31a688 @steelbrain steelbrain committed Jan 24, 2016
Showing with 180 additions and 141 deletions.
  1. +1 โˆ’0 .eslintignore
  2. +19 โˆ’0 lib/helpers.js
  3. +2 โˆ’6 lib/main.js
  4. +1 โˆ’1 lib/reporter.js
  5. +23 โˆ’26 lib/worker-helpers.js
  6. +18 โˆ’18 lib/worker.js
  7. +1 โˆ’1 spec/common.js
  8. +20 โˆ’20 spec/worker-helpers-spec.js
  9. +21 โˆ’5 src/helpers.js
  10. +18 โˆ’17 src/main.js
  11. +1 โˆ’1 src/reporter.js
  12. +32 โˆ’24 src/worker-helpers.js
  13. +23 โˆ’22 src/worker.js
View
@@ -1 +1,2 @@
spec/fixtures/**/*.js
+lib/*.js
View
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.spawnWorker = spawnWorker;
+exports.showError = showError;
var _child_process = require('child_process');
@@ -36,4 +37,22 @@ function spawnWorker() {
return { worker: worker, subscription: new _atom.Disposable(function () {
worker.kill();
}) };
+}
+
+function showError(givenMessage) {
+ let givenDetail = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
+
+ let detail;
+ let message;
+ if (message instanceof Error) {
+ detail = message.stack;
+ message = message.message;
+ } else {
+ detail = givenDetail;
+ message = givenMessage;
+ }
+ atom.notifications.addError(`[Linter-ESLint] ${ message }`, {
+ detail: detail,
+ dismissable: true
+ });
}
View
@@ -1,10 +1,6 @@
'use strict';
'use babel';
-var _path = require('path');
-
-var _path2 = _interopRequireDefault(_path);
-
var _atom = require('atom');
var _helpers = require('./helpers');
@@ -122,7 +118,7 @@ module.exports = {
_this.subscriptions.add(subscription);
worker.onDidExit(function () {
if (_this.active) {
- atom.notifications.addWarning('[Linter-ESLint] Worker died unexpectedly', { detail: 'Check your console for more info. A new worker will be spawned instantly.', dismissable: true });
+ (0, _helpers.showError)('Worker died unexpectedly', 'Check your console for more ' + 'info. A new worker will be spawned instantly.');
setTimeout(initializeWorker, 1000);
}
});
@@ -176,7 +172,7 @@ module.exports = {
range: range
};
if (showRule) {
- ret.html = `<span class="badge badge-flexible">${ ruleId || 'Fatal' }</span> ${ (0, _escapeHtml2.default)(message) }`;
+ ret.html = '<span class="badge badge-flexible">' + (ruleId || 'Fatal') + '</span> ' + (0, _escapeHtml2.default)(message);
} else {
ret.text = message;
}
View
@@ -1,5 +1,5 @@
'use strict'
// This file is used by eslint to hand the errors over to the worker
-module.exports = function(results) {
+module.exports = function (results) {
global.__LINTER_ESLINT_RESPONSE = results[0].messages
}
View
@@ -4,10 +4,10 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
-exports.getESLintInstance = getESLintInstance;
+exports.getNodePrefixPath = getNodePrefixPath;
exports.getESLintFromDirectory = getESLintFromDirectory;
exports.refreshModulesPath = refreshModulesPath;
-exports.getNodePrefixPath = getNodePrefixPath;
+exports.getESLintInstance = getESLintInstance;
exports.getConfigPath = getConfigPath;
exports.getRelativePath = getRelativePath;
exports.getArgv = getArgv;
@@ -16,10 +16,6 @@ var _path = require('path');
var _path2 = _interopRequireDefault(_path);
-var _fs = require('fs');
-
-var _fs2 = _interopRequireDefault(_fs);
-
var _child_process = require('child_process');
var _child_process2 = _interopRequireDefault(_child_process);
@@ -38,10 +34,16 @@ const Cache = {
LAST_MODULES_PATH: null
};
-function getESLintInstance(fileDir, config) {
- const modulesDir = (0, _atomLinter.findCached)(fileDir, 'node_modules');
- refreshModulesPath(modulesDir);
- return getESLintFromDirectory(modulesDir, config);
+function getNodePrefixPath() {
+ if (Cache.NODE_PREFIX_PATH === null) {
+ const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
+ try {
+ Cache.NODE_PREFIX_PATH = _child_process2.default.spawnSync(npmCommand, ['get', 'prefix']).output[1].toString().trim();
+ } catch (e) {
+ throw new Error('Unable to execute `npm get prefix`. Please make sure Atom is getting $PATH correctly');
+ }
+ }
+ return Cache.NODE_PREFIX_PATH;
}
function getESLintFromDirectory(modulesDir, config) {
@@ -75,16 +77,10 @@ function refreshModulesPath(modulesDir) {
}
}
-function getNodePrefixPath() {
- if (Cache.NODE_PREFIX_PATH === null) {
- const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
- try {
- Cache.NODE_PREFIX_PATH = _child_process2.default.spawnSync(npmCommand, ['get', 'prefix']).output[1].toString().trim();
- } catch (e) {
- throw new Error('Unable to execute `npm get prefix`. Please make sure Atom is getting $PATH correctly');
- }
- }
- return Cache.NODE_PREFIX_PATH;
+function getESLintInstance(fileDir, config) {
+ const modulesDir = (0, _atomLinter.findCached)(fileDir, 'node_modules');
+ refreshModulesPath(modulesDir);
+ return getESLintFromDirectory(modulesDir, config);
}
function getConfigPath(fileDir) {
@@ -107,16 +103,17 @@ function getRelativePath(fileDir, filePath, config) {
const ignoreDir = _path2.default.dirname(ignoreFile);
process.chdir(ignoreDir);
return _path2.default.relative(ignoreDir, filePath);
- } else {
- process.chdir(fileDir);
- return _path2.default.basename(filePath);
}
+ process.chdir(fileDir);
+ return _path2.default.basename(filePath);
}
-function getArgv(type, config, filePath, fileDir, configPath) {
- if (configPath === null) {
+function getArgv(type, config, filePath, fileDir, givenConfigPath) {
+ let configPath;
+ if (givenConfigPath === null) {
configPath = config.eslintrcPath || null;
- }
+ } else configPath = givenConfigPath;
+
const argv = [process.execPath, 'a-b-c' // dummy value for eslint cwd
];
if (type === 'lint') {
View
@@ -22,6 +22,24 @@ process.title = 'linter-eslint helper';
const IGNORED_MESSAGE = 'File ignored because of your .eslintignore file. Use --no-ignore to override.';
+function lintJob(argv, contents, eslint, configPath, config) {
+ if (configPath === null && config.disableWhenNoEslintConfig) {
+ return [];
+ }
+ eslint.execute(argv, contents);
+ return global.__LINTER_ESLINT_RESPONSE.filter(function (e) {
+ return e.message !== IGNORED_MESSAGE;
+ });
+}
+function fixJob(argv, eslint) {
+ try {
+ eslint.execute(argv);
+ return 'Linter-ESLint: Fix Complete';
+ } catch (err) {
+ throw new Error('Linter-ESLint: Fix Attempt Completed, Linting Errors Remain');
+ }
+}
+
(0, _processCommunication.create)().onRequest('job', function (_ref, job) {
let contents = _ref.contents;
let type = _ref.type;
@@ -48,22 +66,4 @@ const IGNORED_MESSAGE = 'File ignored because of your .eslintignore file. Use --
}
});
-function lintJob(argv, contents, eslint, configPath, config) {
- if (configPath === null && config.disableWhenNoEslintConfig) {
- return [];
- }
- eslint.execute(argv, contents);
- return global.__LINTER_ESLINT_RESPONSE.filter(function (e) {
- return e.message !== IGNORED_MESSAGE;
- });
-}
-function fixJob(argv, eslint) {
- try {
- eslint.execute(argv);
- return 'Linter-ESLint: Fix Complete';
- } catch (err) {
- throw new Error('Linter-ESLint: Fix Attempt Completed, Linting Errors Remain');
- }
-}
-
process.exit = function () {/* Stop eslint from closing the daemon */};
View
@@ -2,6 +2,6 @@
const Path = require('path')
-module.exports.getFixturesPath = function(path) {
+module.exports.getFixturesPath = function (path) {
return Path.join(__dirname, 'fixtures', path)
}
@@ -1,78 +1,78 @@
'use babel'
import * as Helpers from '../lib/worker-helpers'
-import {getFixturesPath} from './common'
+import { getFixturesPath } from './common'
import * as Path from 'path'
-describe('Worker Helpers', function() {
-
- describe('getESLintInstance && getESLintFromDirectory', function() {
- it('tries to find a local eslint', function() {
+describe('Worker Helpers', function () {
+ describe('getESLintInstance && getESLintFromDirectory', function () {
+ it('tries to find a local eslint', function () {
const eslint = Helpers.getESLintInstance(getFixturesPath('local-eslint'), {})
expect(eslint).toBe('located')
})
- it('cries if local eslint is not found', function() {
- expect(function() {
+ it('cries if local eslint is not found', function () {
+ expect(function () {
Helpers.getESLintInstance(getFixturesPath('files', {}))
}).toThrow()
})
- it('tries to find a global eslint if config is specified', function() {
+ it('tries to find a global eslint if config is specified', function () {
const eslint = Helpers.getESLintInstance(getFixturesPath('local-eslint'), {
useGlobalEslint: true,
globalNodePath: getFixturesPath('global-eslint')
})
expect(eslint).toBe('located')
})
- it('cries if global eslint is not found', function() {
- expect(function() {
+ it('cries if global eslint is not found', function () {
+ expect(function () {
Helpers.getESLintInstance(getFixturesPath('local-eslint'), {
useGlobalEslint: true
})
}).toThrow()
})
})
- describe('getConfigPath', function() {
- it('finds .eslintrc', function() {
+ describe('getConfigPath', function () {
+ it('finds .eslintrc', function () {
const fileDir = getFixturesPath('configs/no-ext/')
const expectedPath = Path.join(fileDir, '.eslintrc')
expect(Helpers.getConfigPath(fileDir)).toBe(expectedPath)
})
- it('finds .eslintrc.yaml', function() {
+ it('finds .eslintrc.yaml', function () {
const fileDir = getFixturesPath('configs/yaml/')
const expectedPath = Path.join(fileDir, '.eslintrc.yaml')
expect(Helpers.getConfigPath(fileDir)).toBe(expectedPath)
})
- it('finds .eslintrc.yml', function() {
+ it('finds .eslintrc.yml', function () {
const fileDir = getFixturesPath('configs/yml/')
const expectedPath = Path.join(fileDir, '.eslintrc.yml')
expect(Helpers.getConfigPath(fileDir)).toBe(expectedPath)
})
- it('finds .eslintrc.js', function() {
+ it('finds .eslintrc.js', function () {
const fileDir = getFixturesPath('configs/js/')
const expectedPath = Path.join(fileDir, '.eslintrc.js')
expect(Helpers.getConfigPath(fileDir)).toBe(expectedPath)
})
- it('finds .eslintrc.json', function() {
+ it('finds .eslintrc.json', function () {
const fileDir = getFixturesPath('configs/json/')
const expectedPath = Path.join(fileDir, '.eslintrc.json')
expect(Helpers.getConfigPath(fileDir)).toBe(expectedPath)
})
})
- describe('getRelativePath', function() {
- it('return path relative of ignore file if found', function() {
+ describe('getRelativePath', function () {
+ it('return path relative of ignore file if found', function () {
const fixtureDir = getFixturesPath('eslintignore')
const fixtureFile = Path.join(fixtureDir, 'ignored.js')
const relativePath = Helpers.getRelativePath(fixtureDir, fixtureFile, {})
const expectedPath = Path.relative(__dirname + '/../', fixtureFile)
expect(relativePath).toBe(expectedPath)
})
- it('does not return path relative to ignore file if config overrides it', function() {
+ it('does not return path relative to ignore file if config overrides it', function () {
const fixtureDir = getFixturesPath('eslintignore')
const fixtureFile = Path.join(fixtureDir, 'ignored.js')
- const relativePath = Helpers.getRelativePath(fixtureDir, fixtureFile, {disableEslintIgnore: true})
+ const relativePath =
+ Helpers.getRelativePath(fixtureDir, fixtureFile, { disableEslintIgnore: true })
expect(relativePath).toBe('ignored.js')
})
})
View
@@ -1,8 +1,8 @@
'use babel'
import ChildProcess from 'child_process'
-import {Disposable} from 'atom'
-import {createFromProcess} from 'process-communication'
+import { Disposable } from 'atom'
+import { createFromProcess } from 'process-communication'
export function spawnWorker() {
const env = Object.create(process.env)
@@ -11,7 +11,7 @@ export function spawnWorker() {
delete env.NODE_ENV
delete env.OS
- const child = ChildProcess.fork(__dirname + '/worker.js', [], {env, silent: true})
+ const child = ChildProcess.fork(__dirname + '/worker.js', [], { env, silent: true })
const worker = createFromProcess(child)
child.stdout.on('data', function (chunk) {
@@ -21,7 +21,23 @@ export function spawnWorker() {
console.log('[Linter-ESLint] STDERR', chunk.toString())
})
- return {worker, subscription: new Disposable(function() {
+ return { worker, subscription: new Disposable(function () {
worker.kill()
- })}
+ }) }
+}
+
+export function showError(givenMessage, givenDetail = null) {
+ let detail
+ let message
+ if (message instanceof Error) {
+ detail = message.stack
+ message = message.message
+ } else {
+ detail = givenDetail
+ message = givenMessage
+ }
+ atom.notifications.addError(`[Linter-ESLint] ${message}`, {
+ detail,
+ dismissable: true
+ })
}
Oops, something went wrong.

0 comments on commit 589658e

Please sign in to comment.