Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip nvm aliases in Travis CI rule #64

Merged
merged 2 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
19 changes: 13 additions & 6 deletions rules/travis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/travis/aliases/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js
node_js:
- 'node'
- 'lts/*'
- 'lts/argon'
- 'lts/boron'
- '6'
- '4'
6 changes: 6 additions & 0 deletions test/fixtures/travis/aliases/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "travis",
"engines": {
"node": ">=4"
}
}
1 change: 1 addition & 0 deletions test/fixtures/travis/deprecated/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: node_js
node_js:
- 'stable'
- 'unstable'
- 'iojs'
- '0.12'
- '0.10'
10 changes: 10 additions & 0 deletions test/travis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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,
Expand Down