From 40518cafbd1874eed80f156e574ef5100279bc1f Mon Sep 17 00:00:00 2001 From: Jakob Krigovsky Date: Thu, 2 Feb 2017 18:53:24 +0100 Subject: [PATCH] skip nvm aliases in Travis CI rule (#64) --- rules/travis.js | 19 +++++++++++++------ test/fixtures/travis/aliases/.travis.yml | 8 ++++++++ test/fixtures/travis/aliases/package.json | 6 ++++++ test/fixtures/travis/deprecated/.travis.yml | 1 + test/travis.js | 10 ++++++++++ 5 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/travis/aliases/.travis.yml create mode 100644 test/fixtures/travis/aliases/package.json diff --git a/rules/travis.js b/rules/travis.js index 1cdf6ad..debb4fb 100644 --- a/rules/travis.js +++ b/rules/travis.js @@ -2,7 +2,8 @@ const semver = require('semver'); const SUPPORTED_VERSIONS = ['0.10', '0.12', '4', '6']; -const DEPRECATED_VERSIONS = ['iojs', 'stable']; +const DEPRECATED_VERSIONS = ['iojs', 'stable', 'unstable']; +const IGNORED_VERSIONS = ['node', 'lts/*', 'lts/argon', 'lts/boron']; /** * Normalize a semantic version to be a valid version. 0.10 -> 0.10.0 @@ -74,22 +75,28 @@ module.exports = ctx => { }); } - const versions = Array.isArray(travis.node_js) ? travis.node_js : [travis.node_js]; + let versions = Array.isArray(travis.node_js) ? travis.node_js : [travis.node_js]; - for (const version of versions) { - if (DEPRECATED_VERSIONS.indexOf(version) !== -1) { + versions = versions.filter(version => { + if (IGNORED_VERSIONS.indexOf(version) !== -1) { + return false; + } else if (DEPRECATED_VERSIONS.indexOf(version) !== -1) { ctx.report({ message: `Version \`${version}\` is deprecated.`, file }); - } else if (version !== 'node' && engine && !semver.satisfies(normalize(version), engine)) { + + return false; + } else if (engine && !semver.satisfies(normalize(version), engine)) { ctx.report({ message: `Unsupported version \`${version}\` is being tested.`, fix: fixers.unsupported(version), file }); } - } + + return true; + }); if (engine) { for (const version of SUPPORTED_VERSIONS) { diff --git a/test/fixtures/travis/aliases/.travis.yml b/test/fixtures/travis/aliases/.travis.yml new file mode 100644 index 0000000..07c18df --- /dev/null +++ b/test/fixtures/travis/aliases/.travis.yml @@ -0,0 +1,8 @@ +language: node_js +node_js: + - 'node' + - 'lts/*' + - 'lts/argon' + - 'lts/boron' + - '6' + - '4' diff --git a/test/fixtures/travis/aliases/package.json b/test/fixtures/travis/aliases/package.json new file mode 100644 index 0000000..e7e7f66 --- /dev/null +++ b/test/fixtures/travis/aliases/package.json @@ -0,0 +1,6 @@ +{ + "name": "travis", + "engines": { + "node": ">=4" + } +} diff --git a/test/fixtures/travis/deprecated/.travis.yml b/test/fixtures/travis/deprecated/.travis.yml index dbe2a61..cb051a1 100644 --- a/test/fixtures/travis/deprecated/.travis.yml +++ b/test/fixtures/travis/deprecated/.travis.yml @@ -1,6 +1,7 @@ language: node_js node_js: - 'stable' + - 'unstable' - 'iojs' - '0.12' - '0.10' diff --git a/test/travis.js b/test/travis.js index e30c862..4518767 100644 --- a/test/travis.js +++ b/test/travis.js @@ -106,6 +106,10 @@ test('untested versions', async t => { ); }); +test('aliases', async t => { + await ruleTester(t, 'aliases', []); +}); + test('deprecated versions', async t => { const file = path.resolve(opts.cwd, 'deprecated/.travis.yml'); @@ -117,6 +121,12 @@ test('deprecated versions', async t => { ruleId: 'travis', severity: 'error' }, + { + message: 'Version `unstable` is deprecated.', + file, + ruleId: 'travis', + severity: 'error' + }, { message: 'Version `iojs` is deprecated.', file,