-
Notifications
You must be signed in to change notification settings - Fork 9
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
Skip nvm aliases in Travis CI rule #64
Conversation
And to which version is @sindresorhus any remarks? |
I am a bit more in favor of ignoring the |
I agree |
Good point. @sonicdoe do you happen to have a reference of Let's ignore In order to ignore |
nvm itself lists I have updated this pull request and opened another one deprecating |
rules/travis.js
Outdated
} | ||
} | ||
|
||
versions = versions.filter(v => DEPRECATED_VERSIONS.indexOf(v) === -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could have merged this filter with the above for…of loop, however, I think that the code is more readable this way and the performance impact is negligible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking back at the code and wondering why we can't write the above for loop like what we had before.
for (const version of versions) {
if (DEPRECATED_VERSIONS.indexOf(version) !== -1) {
ctx.report({
message: `Version \`${version}\` is deprecated.`,
file
});
} else if (engine && !semver.satisfies(normalize(version), engine)) {
ctx.report({
message: `Unsupported version \`${version}\` is being tested.`,
fix: fixers.unsupported(version),
file
});
}
}
I believe this does the same thing as your code with 2 for-loops without having to filter out the deprecated versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would then have to filter out the deprecated versions again in the if (engine)
block further down. Like you said:
In order to ignore node decently, I'd suggest just using filter on the versions array so we don't have to take that one into account further down in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, you're right. Thanks for clarifying.
Although, maybe it might be a better idea to merge the two for..of loops and filter the versions
array again after that for..of loop right before we enter the if (engine)
block. I think it's just weird that we would do it in two loops while we can easily do it in one loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about merging them all into one filter?
let versions = Array.isArray(travis.node_js) ? travis.node_js : [travis.node_js];
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
});
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;
});
This is what I initially tried to avoid but, on second thought, it might not be so bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Just deprecate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also add extra tests for the lts
aliases. Also, if you moved #65 into this one, add an extra test for unstable
.
rules/travis.js
Outdated
@@ -74,15 +75,23 @@ 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]; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the empty line
Done. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also wondering if we should assign a semver version to the LTS aliases like this
const ALIASES = {
'lts/argon': '4',
'lts/boron': '6'
};
If someone sets the node engines to >=6
and he is testing for lts/argon
we can exit and show an error that lts/argon
is not supported.
But this might be out of reach of this PR. We could create a new issue for that afterwards.
rules/travis.js
Outdated
} | ||
} | ||
|
||
versions = versions.filter(v => DEPRECATED_VERSIONS.indexOf(v) === -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm looking back at the code and wondering why we can't write the above for loop like what we had before.
for (const version of versions) {
if (DEPRECATED_VERSIONS.indexOf(version) !== -1) {
ctx.report({
message: `Version \`${version}\` is deprecated.`,
file
});
} else if (engine && !semver.satisfies(normalize(version), engine)) {
ctx.report({
message: `Unsupported version \`${version}\` is being tested.`,
fix: fixers.unsupported(version),
file
});
}
}
I believe this does the same thing as your code with 2 for-loops without having to filter out the deprecated versions.
When running clinton against a package with an
engines
field andnode
in.travis.yml
it crashes withTypeError: Invalid Version: node.0.0
. A similar error was already reported in #46.With this change it now skips all nvm aliases in
isSupported()
. It still crashes when using theunstable
alias but I suggest resolving this by addingunstable
to the list of deprecated versions.