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

Commit

Permalink
Merge pull request #362 from AtomLinter/arcanemagus/eslint-config-air…
Browse files Browse the repository at this point in the history
…bnb-base-11.0.0

Update to eslint-config-airbnb-base v11.0.0
  • Loading branch information
Arcanemagus authored Dec 13, 2016
2 parents 9807cff + ce0c9a5 commit afa9f78
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 164 deletions.
159 changes: 83 additions & 76 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,166 +1,173 @@
'use babel'
'use babel';

/* @flow */

import Path from 'path'
// eslint-disable-next-line import/extensions
import { CompositeDisposable } from 'atom'

type Linter$Provider = Object
import Path from 'path';
// eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
import { CompositeDisposable } from 'atom';

module.exports = {
config: {
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')
provideLinter() {
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 (_) {
console.error('[Linter-JSHint]', _, result)
// eslint-disable-next-line no-console
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;
}

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

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

const error = entry.error
const errorType = error.code.substr(0, 1)
const errorLine = error.line > 0 ? error.line - 1 : 0
let range
const error = entry.error;
const errorType = error.code.substr(0, 1);
let type = 'Info';
if (errorType === 'E') {
type = 'Error';
} else if (errorType === 'W') {
type = 'Warning';
}
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: errorType === 'E' ? 'Error' : errorType === 'W' ? 'Warning' : 'Info',
type,
text: `${error.code} - ${error.reason}`,
filePath,
range
})
}
return results
}
}
}
}
range,
});
});
return results;
},
};
},
};
31 changes: 5 additions & 26 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "MIT",
"scripts": {
"test": "apm test",
"lint": "eslint lib spec"
"lint": "eslint ."
},
"package-deps": [
"linter"
Expand All @@ -19,48 +19,27 @@
"jshint-json": "^1.0.0"
},
"devDependencies": {
"babel-eslint": "^7.0.0",
"eslint": "^3.6.0",
"eslint-config-airbnb-base": "^8.0.0",
"eslint-plugin-babel": "^3.3.0",
"eslint-plugin-import": "^1.16.0"
"eslint": "^3.12.0",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-import": "^2.2.0"
},
"eslintConfig": {
"rules": {
"comma-dangle": [
"error",
"never"
],
"no-console": "off",
"no-continue": "off",
"semi": [
"error",
"never"
],
"global-require": "off",
"no-nested-ternary": "off",
"import/no-unresolved": [
"error",
{
"ignore": [
"atom"
]
}
],
"import/no-extraneous-dependencies": "off",
"arrow-parens": "off",
"babel/arrow-parens": "error"
]
},
"plugins": [
"babel"
],
"extends": "airbnb-base",
"parser": "babel-eslint",
"globals": {
"atom": true
},
"env": {
"es6": true,
"node": true
}
},
Expand Down
Loading

0 comments on commit afa9f78

Please sign in to comment.