From f08bccdf628bd641129497907099596c50e6b19a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 14 Jan 2020 20:55:24 -0600 Subject: [PATCH 1/4] fix(deps): update coffeelint --- package-lock.json | 74 ++++++++++++++++++++++++++++------------------- package.json | 2 +- src/worker.js | 20 +++++++++---- 3 files changed, 59 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7f52996..a5b76a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,49 @@ } } }, + "@coffeelint/cli": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@coffeelint/cli/-/cli-3.0.0.tgz", + "integrity": "sha512-GLK7KPGNIor+Aq2awW2x8pBop16lxXkPhxLnQ7yVsPX3qQu6CtzXL3dcfeNFdijc3Js8oNG5vJnAGTMYHIsTbA==", + "requires": { + "coffeescript": "2.4.1", + "glob": "^7.1.6", + "ignore": "^3.0.9", + "optimist": "^0.6.1", + "resolve": "^0.6.3", + "strip-json-comments": "^1.0.2" + }, + "dependencies": { + "coffeescript": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.4.1.tgz", + "integrity": "sha512-34GV1aHrsMpTaO3KfMJL40ZNuvKDR/g98THHnE9bQj8HjMaZvSrLik99WWqyMhRtbe8V5hpx5iLgdcSvM/S2wg==" + }, + "glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "requires": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + } + }, + "ignore": { + "version": "3.3.10", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", + "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==" + }, + "resolve": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-0.6.3.tgz", + "integrity": "sha1-3ZV5gufnNt699TtYpN2RdUV13UY=" + } + } + }, "@commitlint/cli": { "version": "8.3.4", "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-8.3.4.tgz", @@ -1750,36 +1793,6 @@ } } }, - "coffeelint": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/coffeelint/-/coffeelint-2.1.0.tgz", - "integrity": "sha1-r2XfNjTpmdmsAUgHNsNtPNL12tg=", - "requires": { - "coffeescript": "^2.1.0", - "glob": "^7.0.6", - "ignore": "^3.0.9", - "optimist": "^0.6.1", - "resolve": "^0.6.3", - "strip-json-comments": "^1.0.2" - }, - "dependencies": { - "ignore": { - "version": "3.3.10", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-3.3.10.tgz", - "integrity": "sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==" - }, - "resolve": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-0.6.3.tgz", - "integrity": "sha1-3ZV5gufnNt699TtYpN2RdUV13UY=" - } - } - }, - "coffeescript": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/coffeescript/-/coffeescript-2.3.2.tgz", - "integrity": "sha512-YObiFDoukx7qPBi/K0kUKyntEZDfBQiqs/DbrR1xzASKOBjGT7auD85/DiPeRr9k++lRj7l3uA9TNMLfyfcD/Q==" - }, "collection-visit": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/collection-visit/-/collection-visit-1.0.0.tgz", @@ -3131,6 +3144,7 @@ "version": "7.1.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", diff --git a/package.json b/package.json index d3ad350..31db7ef 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/worker.js b/src/worker.js index 6934ecb..eb874ab 100644 --- a/src/worker.js +++ b/src/worker.js @@ -12,12 +12,20 @@ const resolveCoffeeLint = (filePath) => { 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 (e1) { + if (!e1.message.startsWith("Cannot find module 'coffeelint/package.json'")) { + throw e1; + } + try { + return path.dirname(resolve.sync('@coffeelint/cli/package.json', { + basedir: path.dirname(filePath), + })); + } catch (e2) { + if (!e2.message.startsWith("Cannot find module '@coffeelint/cli/package.json'")) { + throw e2; + } + return '@coffeelint/cli'; } - throw e; } }; @@ -70,7 +78,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`); From c37b9bcf362da928f810f98cb4c7fba7a50cf273 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Tue, 14 Jan 2020 21:44:29 -0600 Subject: [PATCH 2/4] test: @coffeelint/cli in project --- spec/fixtures/valid_coffeelint_cli/coffeelint.json | 5 +++++ .../node_modules/@coffeelint/cli/lib/coffeelint.js | 6 ++++++ .../node_modules/@coffeelint/cli/lib/configfinder.js | 3 +++ .../node_modules/@coffeelint/cli/package.json | 3 +++ spec/fixtures/valid_coffeelint_cli/valid.coffee | 4 ++++ spec/linter-coffeelint-spec.js | 12 ++++++++++++ 6 files changed, 33 insertions(+) create mode 100644 spec/fixtures/valid_coffeelint_cli/coffeelint.json create mode 100644 spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/coffeelint.js create mode 100644 spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/configfinder.js create mode 100644 spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/package.json create mode 100644 spec/fixtures/valid_coffeelint_cli/valid.coffee diff --git a/spec/fixtures/valid_coffeelint_cli/coffeelint.json b/spec/fixtures/valid_coffeelint_cli/coffeelint.json new file mode 100644 index 0000000..7c0479d --- /dev/null +++ b/spec/fixtures/valid_coffeelint_cli/coffeelint.json @@ -0,0 +1,5 @@ +{ + "arrow_spacing": { + "level": "warn" + } +} diff --git a/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/coffeelint.js b/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/coffeelint.js new file mode 100644 index 0000000..2e6fe52 --- /dev/null +++ b/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/coffeelint.js @@ -0,0 +1,6 @@ +module.exports = { + VERSION: '100.0.0', + lint: () => [{ + level: 'warn', message: 'test message', rule: 'test rule', lineNumber: 1, + }], +}; diff --git a/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/configfinder.js b/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/configfinder.js new file mode 100644 index 0000000..633fc91 --- /dev/null +++ b/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/lib/configfinder.js @@ -0,0 +1,3 @@ +module.exports = { + getConfig: () => ({}), +}; diff --git a/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/package.json b/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/package.json new file mode 100644 index 0000000..22c205b --- /dev/null +++ b/spec/fixtures/valid_coffeelint_cli/node_modules/@coffeelint/cli/package.json @@ -0,0 +1,3 @@ +{ + "main": "./lib/coffeelint.js" +} diff --git a/spec/fixtures/valid_coffeelint_cli/valid.coffee b/spec/fixtures/valid_coffeelint_cli/valid.coffee new file mode 100644 index 0000000..619c564 --- /dev/null +++ b/spec/fixtures/valid_coffeelint_cli/valid.coffee @@ -0,0 +1,4 @@ +# Both of this will not trigger an error, +# even with arrow_spacing enabled. +x(-> 3) +x( -> 3) diff --git a/spec/linter-coffeelint-spec.js b/spec/linter-coffeelint-spec.js index eab83bb..c124128 100644 --- a/spec/linter-coffeelint-spec.js +++ b/spec/linter-coffeelint-spec.js @@ -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'); @@ -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); From 1a1446fff797d70c45f7e364c322d75bca3caa02 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 15 Jan 2020 10:15:06 -0600 Subject: [PATCH 3/4] fix: refactor resolve coffeelint in package --- src/worker.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/worker.js b/src/worker.js index eb874ab..09fc2f2 100644 --- a/src/worker.js +++ b/src/worker.js @@ -9,24 +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 (e1) { - if (!e1.message.startsWith("Cannot find module 'coffeelint/package.json'")) { - throw e1; + } catch (ex) { + if (!ex.message.startsWith("Cannot find module 'coffeelint/package.json'")) { + throw ex; } - try { - return path.dirname(resolve.sync('@coffeelint/cli/package.json', { - basedir: path.dirname(filePath), - })); - } catch (e2) { - if (!e2.message.startsWith("Cannot find module '@coffeelint/cli/package.json'")) { - throw e2; - } - return '@coffeelint/cli'; + } + + 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) => { @@ -66,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; From 72fe782a3248f84ce5d3a01733368320545c7f5b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 15 Jan 2020 10:19:25 -0600 Subject: [PATCH 4/4] docs: update docs to use new @coffeelint/cli --- README.md | 4 ++-- local_upgrade.md | 4 ++-- src/worker.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 15fab96..a794e92 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/local_upgrade.md b/local_upgrade.md index 82c89f1..93e5d37 100644 --- a/local_upgrade.md +++ b/local_upgrade.md @@ -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` diff --git a/src/worker.js b/src/worker.js index 09fc2f2..7725375 100644 --- a/src/worker.js +++ b/src/worker.js @@ -113,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', }); }