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

Commit

Permalink
Update coffeelint (#241)
Browse files Browse the repository at this point in the history
Update coffeelint
  • Loading branch information
UziTech committed Jan 15, 2020
2 parents b973fb8 + a1d596e commit dd5db09
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#linter-coffeelint

This linter plugin for [Linter](https://github.com/AtomLinter/Linter) provides an interface to
[coffeelint](http://www.coffeelint.org/). It will be used with files that have the “CoffeeScript”
[coffeelint](https://coffeelint.github.io/coffeelint/). It will be used with files that have the “CoffeeScript”
or “CoffeeScript (literate)” syntax.

## Installation
Expand All @@ -29,7 +29,7 @@ As of v0.2.0 there is no need to specify a path to coffeelint. If you need to us
version you can specify it in your project's `package.json` and `linter-coffeelint` will use that
one. This is the same behavior the coffeelint commandline gives you.

[How do I configure CoffeeLint?](https://github.com/clutchski/coffeelint/blob/master/doc/user.md)
[How do I configure CoffeeLint?](https://github.com/coffeelint/coffeelint/blob/master/doc/user.md)

## Contributing

Expand Down
4 changes: 2 additions & 2 deletions local_upgrade.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
linter-coffeelint will prefer to use the version of CoffeeLint you have installed in your project (`npm install --save-dev coffeelint`).
linter-coffeelint will prefer to use the version of CoffeeLint you have installed in your project (`npm install --save-dev @coffeelint/cli`).

If you've been directed here it means your local coffeelint is in some way incompatible with linter-coffeelint. You need to upgrade with `npm install --save-dev coffeelint@latest`
If you've been directed here it means your local coffeelint is in some way incompatible with linter-coffeelint. You need to upgrade with `npm install --save-dev @coffeelint/cli@latest`
74 changes: 44 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"atom-linter": "10.0.0",
"atom-package-deps": "5.1.0",
"coffeelint": "2.1.0",
"@coffeelint/cli": "3.0.0",
"ignore": "5.1.4",
"resolve": "1.14.2",
"semver": "7.1.1"
Expand Down
5 changes: 5 additions & 0 deletions spec/fixtures/valid_coffeelint_cli/coffeelint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"arrow_spacing": {
"level": "warn"
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions spec/fixtures/valid_coffeelint_cli/valid.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Both of this will not trigger an error,
# even with arrow_spacing enabled.
x(-> 3)
x( -> 3)
12 changes: 12 additions & 0 deletions spec/linter-coffeelint-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const fixturesPath = join(__dirname, 'fixtures');
const validPath = join(fixturesPath, 'valid', 'valid.coffee');
const invalidLevelPath = join(fixturesPath, 'invalid-level', 'valid.coffee');
const validCoffeelintPath = join(fixturesPath, 'valid_coffeelint', 'valid.coffee');
const validCoffeelintCliPath = join(fixturesPath, 'valid_coffeelint_cli', 'valid.coffee');
const arrowSpacingPath = join(fixturesPath, 'arrow_spacing', 'arrow_spacing.coffee');
const arrowSpacingWarningPath = join(fixturesPath, 'arrow_spacing_warning', 'arrow_spacing.coffee');
const noConfigPath = join(fixturesPath, 'no_config', 'no_config.coffee');
Expand Down Expand Up @@ -78,6 +79,17 @@ describe('The CoffeeLint provider for Linter', () => {
expect(messages[0].location.position).toEqual([[0, 0], [0, 41]]);
});

it('uses @coffeelint/cli from the project', async () => {
const editor = await atom.workspace.open(validCoffeelintCliPath);
const messages = await linter.lint(editor);

expect(messages.length).toBe(1);
expect(messages[0].severity).toBe('warning');
expect(messages[0].excerpt).toBe('test message. (test rule)');
expect(messages[0].location.file).toBe(validCoffeelintCliPath);
expect(messages[0].location.position).toEqual([[0, 0], [0, 41]]);
});

it('gives the error on config error', async () => {
const editor = await atom.workspace.open(invalidLevelPath);
const messages = await linter.lint(editor);
Expand Down
28 changes: 20 additions & 8 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@ const fs = require('fs');

const resolveCoffeeLint = (filePath) => {
try {
// check for coffeelint in project
return path.dirname(resolve.sync('coffeelint/package.json', {
basedir: path.dirname(filePath),
}));
} catch (e) {
const expected = "Cannot find module 'coffeelint/package.json'";
if (e.message.slice(0, expected.length) === expected) {
return 'coffeelint';
} catch (ex) {
if (!ex.message.startsWith("Cannot find module 'coffeelint/package.json'")) {
throw ex;
}
throw e;
}

try {
// check for @coffeelint/cli in project
return path.dirname(resolve.sync('@coffeelint/cli/package.json', {
basedir: path.dirname(filePath),
}));
} catch (ex) {
if (!ex.message.startsWith("Cannot find module '@coffeelint/cli/package.json'")) {
throw ex;
}
}

return '@coffeelint/cli';
};

const configImportsModules = (config) => {
Expand Down Expand Up @@ -58,7 +70,7 @@ module.exports = (filePath, source, isLiterate, linterConfig) => {
// this assumption, so CoffeeLint < 1.9.1 will fail to find CoffeeScript.
// See https://github.com/clutchski/coffeelint/pull/383
if (semver.lt(coffeelint.VERSION, '1.9.1')) {
coffeeLintPath = 'coffeelint';
coffeeLintPath = '@coffeelint/cli';
// eslint-disable-next-line import/no-dynamic-require
coffeelint = require(coffeeLintPath);
showUpgradeError = true;
Expand All @@ -70,7 +82,7 @@ module.exports = (filePath, source, isLiterate, linterConfig) => {

if (!showUpgradeError) {
if (configImportsModules(config) && semver.lt(coffeelint.VERSION, '1.9.5')) {
coffeeLintPath = 'coffeelint';
coffeeLintPath = '@coffeelint/cli';
/* eslint-disable import/no-dynamic-require */
coffeelint = require(coffeeLintPath);
configFinder = require(`${coffeeLintPath}/lib/configfinder`);
Expand Down Expand Up @@ -101,7 +113,7 @@ module.exports = (filePath, source, isLiterate, linterConfig) => {
results.push({
lineNumber: 1,
level: 'error',
message: "http://git.io/local_upgrade upgrade your project's CoffeeLint",
message: "https://git.io/local_upgrade upgrade your project's CoffeeLint",
rule: 'none',
});
}
Expand Down

0 comments on commit dd5db09

Please sign in to comment.