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

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcanemagus committed Sep 21, 2016
1 parent cdf5206 commit df69299
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 61 deletions.
13 changes: 8 additions & 5 deletions lib/helpers.js
Expand Up @@ -11,12 +11,12 @@ var _child_process = require('child_process');

var _child_process2 = _interopRequireDefault(_child_process);

var _atom = require('atom');

var _processCommunication = require('process-communication');

var _path = require('path');

var _atom = require('atom');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function spawnWorker() {
Expand All @@ -36,11 +36,14 @@ function spawnWorker() {
console.log('[Linter-ESLint] STDERR', chunk.toString());
});

return { worker: worker, subscription: new _atom.Disposable(function () {
return {
worker: worker,
subscription: new _atom.Disposable(function () {
worker.kill();
}) };
})
};
}

// eslint-disable-next-line import/no-extraneous-dependencies
function showError(givenMessage) {
var givenDetail = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];

Expand Down
16 changes: 8 additions & 8 deletions lib/main.js
@@ -1,10 +1,6 @@
'use strict';
'use babel';

var _atom = require('atom');

var _helpers = require('./helpers');

var _escapeHtml = require('escape-html');

var _escapeHtml2 = _interopRequireDefault(_escapeHtml);
Expand All @@ -13,8 +9,13 @@ var _eslintRuleDocumentation = require('eslint-rule-documentation');

var _eslintRuleDocumentation2 = _interopRequireDefault(_eslintRuleDocumentation);

var _atom = require('atom');

var _helpers = require('./helpers');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// eslint-disable-next-line import/no-extraneous-dependencies
module.exports = {
activate: function activate() {
var _this = this;
Expand All @@ -36,10 +37,8 @@ module.exports = {
this.subscriptions.add(atom.config.observe('linter-eslint.lintHtmlFiles', function (lintHtmlFiles) {
if (lintHtmlFiles) {
_this.scopes.push(embeddedScope);
} else {
if (_this.scopes.indexOf(embeddedScope) !== -1) {
_this.scopes.splice(_this.scopes.indexOf(embeddedScope), 1);
}
} else if (_this.scopes.indexOf(embeddedScope) !== -1) {
_this.scopes.splice(_this.scopes.indexOf(embeddedScope), 1);
}
}));
this.subscriptions.add(atom.workspace.observeTextEditors(function (editor) {
Expand Down Expand Up @@ -103,6 +102,7 @@ module.exports = {
var _this2 = this;

var Helpers = require('atom-linter');

return {
name: 'ESLint',
grammarScopes: this.scopes,
Expand Down
8 changes: 4 additions & 4 deletions lib/worker.js
Expand Up @@ -6,14 +6,14 @@ var _path = require('path');

var _path2 = _interopRequireDefault(_path);

var _workerHelpers = require('./worker-helpers');

var Helpers = _interopRequireWildcard(_workerHelpers);

var _processCommunication = require('process-communication');

var _atomLinter = require('atom-linter');

var _workerHelpers = require('./worker-helpers');

var Helpers = _interopRequireWildcard(_workerHelpers);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Expand Down
41 changes: 16 additions & 25 deletions spec/linter-eslint-spec.js
@@ -1,7 +1,7 @@
'use babel'

import linter from '../lib/main'
import * as path from 'path'
import linter from '../lib/main'

const goodPath = path.join(__dirname, 'fixtures', 'files', 'good.js')
const badPath = path.join(__dirname, 'fixtures', 'files', 'bad.js')
Expand All @@ -16,6 +16,7 @@ const ignoredPath = path.join(__dirname, 'fixtures',

describe('The eslint provider for Linter', () => {
const { spawnWorker } = require('../lib/helpers')

const worker = spawnWorker()
const lint = linter.provideLinter.call(worker).lint

Expand All @@ -33,29 +34,27 @@ describe('The eslint provider for Linter', () => {
let editor = null
beforeEach(() => {
waitsForPromise(() =>
atom.workspace.open(badPath).then(openEditor => {
atom.workspace.open(badPath).then((openEditor) => {
editor = openEditor
})
)
})

it('finds at least one message', () => {
waitsForPromise(() =>
lint(editor).then(messages => {
expect(messages.length).toBeGreaterThan(0)
})
lint(editor).then(messages => expect(messages.length).toBeGreaterThan(0))
)
})

it('verifies that message', () => {
waitsForPromise(() =>
lint(editor).then(messages => {
lint(editor).then((messages) => {
expect(messages[0].type).toBe('Error')
expect(messages[0].html).not.toBeDefined()
expect(messages[0].text).toBe("'foo' is not defined.")
expect(messages[0].filePath).toBe(badPath)
expect(messages[0].range).toEqual([[0, 0], [0, 3]])
expect(messages[0].hasOwnProperty('fix')).toBeFalsy()
expect(Object.hasOwnProperty.call(messages[0], 'fix')).toBeFalsy()
})
)
})
Expand All @@ -64,19 +63,15 @@ describe('The eslint provider for Linter', () => {
it('finds nothing wrong with an empty file', () => {
waitsForPromise(() =>
atom.workspace.open(emptyPath).then(editor =>
lint(editor).then(messages => {
expect(messages.length).toBe(0)
})
lint(editor).then(messages => expect(messages.length).toBe(0))
)
)
})

it('finds nothing wrong with a valid file', () => {
waitsForPromise(() =>
atom.workspace.open(goodPath).then(editor =>
lint(editor).then(messages => {
expect(messages.length).toBe(0)
})
lint(editor).then(messages => expect(messages.length).toBe(0))
)
)
})
Expand All @@ -85,7 +80,7 @@ describe('The eslint provider for Linter', () => {
waitsForPromise(() =>
atom.workspace.open(fixPath).then(editor =>
lint(editor)
).then(messages => {
).then((messages) => {
expect(messages[0].fix.range).toEqual([[0, 11], [0, 12]])
expect(messages[0].fix.newText).toBe('')

Expand All @@ -99,23 +94,21 @@ describe('The eslint provider for Linter', () => {
it('correctly resolves imports from parent', () => {
waitsForPromise(() =>
atom.workspace.open(importingpath).then(editor =>
lint(editor).then(messages => {
expect(messages.length).toBe(0)
})
lint(editor).then(messages => expect(messages.length).toBe(0))
)
)
})
it('shows a message for an invalid import', () => {
waitsForPromise(() =>
atom.workspace.open(badImportPath).then(editor =>
lint(editor).then(messages => {
lint(editor).then((messages) => {
expect(messages.length).toBeGreaterThan(0)
expect(messages[0].type).toBe('Error')
expect(messages[0].html).not.toBeDefined()
expect(messages[0].text).toBe("Unable to resolve path to module '../nonexistent'.")
expect(messages[0].filePath).toBe(badImportPath)
expect(messages[0].range).toEqual([[0, 24], [0, 39]])
expect(messages[0].hasOwnProperty('fix')).toBeFalsy()
expect(Object.hasOwnProperty.call(messages[0], 'fix')).toBeFalsy()
})
)
)
Expand All @@ -129,9 +122,7 @@ describe('The eslint provider for Linter', () => {
it('will not give warnings for the file', () => {
waitsForPromise(() =>
atom.workspace.open(ignoredPath).then(editor =>
lint(editor).then(messages => {
expect(messages.length).toBe(0)
})
lint(editor).then(messages => expect(messages.length).toBe(0))
)
)
})
Expand All @@ -143,11 +134,11 @@ describe('The eslint provider for Linter', () => {
})
it('should fix lint errors when saved', () => {
waitsForPromise(() =>
atom.workspace.open(fixPath).then(editor => {
lint(editor).then(messages => {
atom.workspace.open(fixPath).then((editor) => {
lint(editor).then((messages) => {
expect(messages.length).toBe(2)
editor.save()
lint(editor).then(messagesAfterSave => {
lint(editor).then((messagesAfterSave) => {
expect(messagesAfterSave.length).toBe(0)
})
})
Expand Down
2 changes: 1 addition & 1 deletion spec/worker-helpers-spec.js
@@ -1,8 +1,8 @@
'use babel'

import * as Path from 'path'
import * as Helpers from '../lib/worker-helpers'
import { getFixturesPath } from './common'
import * as Path from 'path'

describe('Worker Helpers', () => {
describe('getESLintInstance && getESLintFromDirectory', () => {
Expand Down
12 changes: 8 additions & 4 deletions src/helpers.js
@@ -1,9 +1,10 @@
'use babel'

import ChildProcess from 'child_process'
import { Disposable } from 'atom'
import { createFromProcess } from 'process-communication'
import { join } from 'path'
// eslint-disable-next-line import/no-extraneous-dependencies
import { Disposable } from 'atom'

export function spawnWorker() {
const env = Object.create(process.env)
Expand All @@ -22,9 +23,12 @@ export function spawnWorker() {
console.log('[Linter-ESLint] STDERR', chunk.toString())
})

return { worker, subscription: new Disposable(() => {
worker.kill()
}) }
return {
worker,
subscription: new Disposable(() => {
worker.kill()
})
}
}

export function showError(givenMessage, givenDetail = null) {
Expand Down
25 changes: 13 additions & 12 deletions src/main.js
@@ -1,9 +1,11 @@
'use babel'

import { CompositeDisposable, Range } from 'atom'
import { spawnWorker, showError } from './helpers'
import escapeHTML from 'escape-html'
import ruleURI from 'eslint-rule-documentation'
// eslint-disable-next-line import/no-extraneous-dependencies
import { CompositeDisposable, Range } from 'atom'

import { spawnWorker, showError } from './helpers'

module.exports = {
activate() {
Expand All @@ -14,20 +16,18 @@ module.exports = {
this.worker = null
this.scopes = []

this.subscriptions.add(atom.config.observe('linter-eslint.scopes', scopes => {
this.subscriptions.add(atom.config.observe('linter-eslint.scopes', (scopes) => {
// Remove any old scopes
this.scopes.splice(0, this.scopes.length)
// Add the current scopes
Array.prototype.push.apply(this.scopes, scopes)
}))
const embeddedScope = 'source.js.embedded.html'
this.subscriptions.add(atom.config.observe('linter-eslint.lintHtmlFiles', lintHtmlFiles => {
this.subscriptions.add(atom.config.observe('linter-eslint.lintHtmlFiles', (lintHtmlFiles) => {
if (lintHtmlFiles) {
this.scopes.push(embeddedScope)
} else {
if (this.scopes.indexOf(embeddedScope) !== -1) {
this.scopes.splice(this.scopes.indexOf(embeddedScope), 1)
}
} else if (this.scopes.indexOf(embeddedScope) !== -1) {
this.scopes.splice(this.scopes.indexOf(embeddedScope), 1)
}
}))
this.subscriptions.add(atom.workspace.observeTextEditors((editor) => {
Expand All @@ -38,7 +38,7 @@ module.exports = {
type: 'fix',
config: atom.config.get('linter-eslint'),
filePath: editor.getPath()
}).catch((response) =>
}).catch(response =>
atom.notifications.addWarning(response)
)
}
Expand All @@ -59,9 +59,9 @@ module.exports = {
type: 'fix',
config: atom.config.get('linter-eslint'),
filePath
}).then((response) =>
}).then(response =>
atom.notifications.addSuccess(response)
).catch((response) =>
).catch(response =>
atom.notifications.addWarning(response)
)
}
Expand All @@ -87,12 +87,13 @@ module.exports = {
},
provideLinter() {
const Helpers = require('atom-linter')

return {
name: 'ESLint',
grammarScopes: this.scopes,
scope: 'file',
lintOnFly: true,
lint: textEditor => {
lint: (textEditor) => {
const text = textEditor.getText()
if (text.length === 0) {
return Promise.resolve([])
Expand Down
5 changes: 3 additions & 2 deletions src/worker.js
@@ -1,11 +1,12 @@
'use babel'
// Note: 'use babel' doesn't work in forked processes
process.title = 'linter-eslint helper'

import Path from 'path'
import * as Helpers from './worker-helpers'
import { create } from 'process-communication'
import { FindCache } from 'atom-linter'
import * as Helpers from './worker-helpers'

process.title = 'linter-eslint helper'

const ignoredMessages = [
// V1
Expand Down

0 comments on commit df69299

Please sign in to comment.