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

Skip nvm aliases in Travis CI rule #64

merged 2 commits into from
Feb 2, 2017

Conversation

sonicdoe
Copy link
Contributor

When running clinton against a package with an engines field and node in .travis.yml it crashes with TypeError: 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 the unstable alias but I suggest resolving this by adding unstable to the list of deprecated versions.

@coveralls
Copy link

coveralls commented Jan 26, 2017

Coverage Status

Coverage increased (+0.02%) to 96.302% when pulling b0179d0 on sonicdoe:skip-nvm-aliases into dc90ac0 on SamVerschueren:master.

@SamVerschueren
Copy link
Owner

SamVerschueren commented Jan 26, 2017

And to which version is node mapped? Latest? As you can see in this line, stable for instance is marked as deprecated. So actually I'm more in favour of marking these versions as not supported because it's not explicit about which versions it tests. Not really sure about it though.

@sindresorhus any remarks?

@sonicdoe
Copy link
Contributor Author

sonicdoe commented Jan 26, 2017

stable was deprecated because it “only truly applies to node v0.12 and earlier”. node always maps to the latest version of Node.js.

I am a bit more in favor of ignoring the node alias as opposed to marking it as an error because it is useful to always test against the latest Node.js version. However, I can understand if users should be urged to keep their .travis.yml up to date.

@sindresorhus
Copy link

I agree node should just be ignored. It can be useful sometimes when you just want the latest Node.js version. Example.

@SamVerschueren
Copy link
Owner

Good point. @sonicdoe do you happen to have a reference of unstable being part of Travis? Can't seem to find it.

Let's ignore node. which seems it was already ignored but somehow fails on some other scenarios which aren't tested. All the other should be moved to the deprecated versions array, which only is the unstable version. But I want proof first of that alias to exist.

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.

@sonicdoe
Copy link
Contributor Author

Travis CI uses nvm:

These values are passed on to nvm; newer releases not shown above may be used if nvm recognizes them.

nvm itself lists node, iojs, stable, and unstable as special default aliases. I have also just realized that there are LTS aliases. Given that these are similar to node, I have added them to the ignore array, too.

I have updated this pull request and opened another one deprecating unstable.

@coveralls
Copy link

coveralls commented Jan 30, 2017

Coverage Status

Coverage increased (+0.02%) to 96.307% when pulling 113249e on sonicdoe:skip-nvm-aliases into dc90ac0 on SamVerschueren:master.

rules/travis.js Outdated
}
}

versions = versions.filter(v => DEPRECATED_VERSIONS.indexOf(v) === -1);
Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good!

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

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.

Copy link
Contributor Author

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@SamVerschueren
Copy link
Owner

I have updated this pull request and opened another one deprecating unstable.

Just deprecate unstable in this PR instead of a new one.

Copy link
Owner

@SamVerschueren SamVerschueren left a 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];

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the empty line

@coveralls
Copy link

coveralls commented Feb 2, 2017

Coverage Status

Coverage increased (+0.02%) to 96.307% when pulling b088fe0 on sonicdoe:skip-nvm-aliases into dc90ac0 on SamVerschueren:master.

@sonicdoe
Copy link
Contributor Author

sonicdoe commented Feb 2, 2017

Done.

Copy link
Owner

@SamVerschueren SamVerschueren left a 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);
Copy link
Owner

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.

@coveralls
Copy link

coveralls commented Feb 2, 2017

Coverage Status

Coverage increased (+0.03%) to 96.312% when pulling 84fb5c3 on sonicdoe:skip-nvm-aliases into dc90ac0 on SamVerschueren:master.

@SamVerschueren SamVerschueren merged commit 40518ca into SamVerschueren:master Feb 2, 2017
@SamVerschueren
Copy link
Owner

Awesome, great work @sonicdoe! I created a follow-up issue #66 for an extra improvement on this rule.

@sonicdoe sonicdoe deleted the skip-nvm-aliases branch February 2, 2017 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants