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

Update to eslint-config-airbnb-base v11.0.0 #362

Merged
merged 4 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rule removal - Stage 2
Re-enable the `comma-dangle` and `semi` rules. The less that we have
configured means the less we have to maintain.
  • Loading branch information
Arcanemagus committed Dec 13, 2016
commit aacb8583bdf32696a0f91660233929d02ee92efd
148 changes: 74 additions & 74 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use babel'
'use babel';

/* @flow */

import Path from 'path'
import Path from 'path';
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
import { CompositeDisposable } from 'atom'
import { CompositeDisposable } from 'atom';

type Linter$Provider = Object

Expand All @@ -13,163 +13,163 @@ module.exports = {
executablePath: {
type: 'string',
default: Path.join(__dirname, '..', 'node_modules', 'jshint', 'bin', 'jshint'),
description: 'Path of the `jshint` node script'
description: 'Path of the `jshint` node script',
},
lintInlineJavaScript: {
type: 'boolean',
default: false,
description: 'Lint JavaScript inside `<script>` blocks in HTML or PHP files.'
description: 'Lint JavaScript inside `<script>` blocks in HTML or PHP files.',
},
disableWhenNoJshintrcFileInPath: {
type: 'boolean',
default: false,
description: 'Disable linter when no `.jshintrc` is found in project.'
description: 'Disable linter when no `.jshintrc` is found in project.',
},
jshintFileName: {
type: 'string',
default: '.jshintrc',
description: 'jshint file name'
}
description: 'jshint file name',
},
},

activate() {
require('atom-package-deps').install('linter-jshint')
require('atom-package-deps').install('linter-jshint');

this.scopes = ['source.js', 'source.js-semantic']
this.subscriptions = new CompositeDisposable()
this.scopes = ['source.js', 'source.js-semantic'];
this.subscriptions = new CompositeDisposable();
this.subscriptions.add(atom.config.observe('linter-jshint.executablePath', (executablePath) => {
this.executablePath = executablePath
}))
this.executablePath = executablePath;
}));
this.subscriptions.add(
atom.config.observe('linter-jshint.disableWhenNoJshintrcFileInPath',
(disableWhenNoJshintrcFileInPath) => {
this.disableWhenNoJshintrcFileInPath = disableWhenNoJshintrcFileInPath
}
)
)
this.disableWhenNoJshintrcFileInPath = disableWhenNoJshintrcFileInPath;
},
),
);

this.subscriptions.add(atom.config.observe('linter-jshint.jshintFileName', (jshintFileName) => {
this.jshintFileName = jshintFileName
}))
this.jshintFileName = jshintFileName;
}));

const scopeEmbedded = 'source.js.embedded.html'
const scopeEmbedded = 'source.js.embedded.html';
this.subscriptions.add(atom.config.observe('linter-jshint.lintInlineJavaScript',
(lintInlineJavaScript) => {
this.lintInlineJavaScript = lintInlineJavaScript
this.lintInlineJavaScript = lintInlineJavaScript;
if (lintInlineJavaScript) {
this.scopes.push(scopeEmbedded)
this.scopes.push(scopeEmbedded);
} else if (this.scopes.indexOf(scopeEmbedded) !== -1) {
this.scopes.splice(this.scopes.indexOf(scopeEmbedded), 1)
this.scopes.splice(this.scopes.indexOf(scopeEmbedded), 1);
}
}
))
},
));
},

deactivate() {
this.subscriptions.dispose()
this.subscriptions.dispose();
},

provideLinter(): Linter$Provider {
const Helpers = require('atom-linter')
const Reporter = require('jshint-json')
const Helpers = require('atom-linter');
const Reporter = require('jshint-json');

return {
name: 'JSHint',
grammarScopes: this.scopes,
scope: 'file',
lintOnFly: true,
lint: async (textEditor) => {
const results = []
const filePath = textEditor.getPath()
const fileContents = textEditor.getText()
const parameters = ['--reporter', Reporter, '--filename', filePath]
const results = [];
const filePath = textEditor.getPath();
const fileContents = textEditor.getText();
const parameters = ['--reporter', Reporter, '--filename', filePath];

const configFile = await Helpers.findCachedAsync(
Path.dirname(filePath), this.jshintFileName
)
Path.dirname(filePath), this.jshintFileName,
);

if (configFile) {
parameters.push('--config', configFile)
parameters.push('--config', configFile);
} else if (this.disableWhenNoJshintrcFileInPath) {
return results
return results;
}

if (this.lintInlineJavaScript &&
textEditor.getGrammar().scopeName.indexOf('text.html') !== -1
) {
parameters.push('--extract', 'always')
parameters.push('--extract', 'always');
}
parameters.push('-')
parameters.push('-');

const execOpts = { stdin: fileContents, ignoreExitCode: true }
const execOpts = { stdin: fileContents, ignoreExitCode: true };
const result = await Helpers.execNode(
this.executablePath, parameters, execOpts
)
this.executablePath, parameters, execOpts,
);

if (textEditor.getText() !== fileContents) {
// File has changed since the lint was triggered, tell Linter not to update
return null
return null;
}

let parsed
let parsed;
try {
parsed = JSON.parse(result)
parsed = JSON.parse(result);
} catch (_) {
// eslint-disable-next-line no-console
console.error('[Linter-JSHint]', _, result)
console.error('[Linter-JSHint]', _, result);
atom.notifications.addWarning('[Linter-JSHint]',
{ detail: 'JSHint return an invalid response, check your console for more info' }
)
return results
{ detail: 'JSHint return an invalid response, check your console for more info' },
);
return results;
}

Object.keys(parsed.result).forEach((entryID) => {
const entry = parsed.result[entryID]
const entry = parsed.result[entryID];

if (!entry.error.id) {
return
return;
}

const error = entry.error
const errorType = error.code.substr(0, 1)
let type = 'Info'
const error = entry.error;
const errorType = error.code.substr(0, 1);
let type = 'Info';
if (errorType === 'E') {
type = 'Error'
type = 'Error';
} else if (errorType === 'W') {
type = 'Warning'
type = 'Warning';
}
const errorLine = error.line > 0 ? error.line - 1 : 0
let range
const errorLine = error.line > 0 ? error.line - 1 : 0;
let range;

// TODO: Remove workaround of jshint/jshint#2846
if (error.character === null) {
range = Helpers.rangeFromLineNumber(textEditor, errorLine)
range = Helpers.rangeFromLineNumber(textEditor, errorLine);
} else {
let character = error.character > 0 ? error.character - 1 : 0
let line = errorLine
const buffer = textEditor.getBuffer()
const maxLine = buffer.getLineCount()
let character = error.character > 0 ? error.character - 1 : 0;
let line = errorLine;
const buffer = textEditor.getBuffer();
const maxLine = buffer.getLineCount();
// TODO: Remove workaround of jshint/jshint#2894
if (errorLine >= maxLine) {
line = maxLine
line = maxLine;
}
const maxCharacter = buffer.lineLengthForRow(line)
const maxCharacter = buffer.lineLengthForRow(line);
// TODO: Remove workaround of jquery/esprima#1457
if (character > maxCharacter) {
character = maxCharacter
character = maxCharacter;
}
range = Helpers.rangeFromLineNumber(textEditor, line, character)
range = Helpers.rangeFromLineNumber(textEditor, line, character);
}

results.push({
type,
text: `${error.code} - ${error.reason}`,
filePath,
range
})
})
return results
}
}
}
}
range,
});
});
return results;
},
};
},
};
8 changes: 0 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
},
"eslintConfig": {
"rules": {
"comma-dangle": [
"error",
"never"
],
"semi": [
"error",
"never"
],
"global-require": "off",
"import/no-unresolved": [
"error",
Expand Down
Loading