Skip to content

add rulesdir option #7

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

Merged
merged 11 commits into from
Apr 25, 2017
Merged

add rulesdir option #7

merged 11 commits into from
Apr 25, 2017

Conversation

Benoit-Vasseur
Copy link
Contributor

Hi,

We are curently using VueJs and to be able to have your loader working we had to use the rulesdir feature of HtmlHint.
We think this could be useful for anyone.
The code is inspired by HtmlHint itself : https://github.com/yaniswang/HTMLHint/blob/152a114f277645474ca1f70d68a0e01e75f3eb51/bin/htmlhint#L142 .

What do you think ?

@Benoit-Vasseur
Copy link
Contributor Author

Dont't understand why the tests are failing :/ They are green on my machine

Copy link
Member

@mattlewis92 mattlewis92 left a comment

Choose a reason for hiding this comment

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

This is looking good, thanks! Could you also add a test for the new feature + document its usage in the readme.

index.js Outdated
@@ -40,11 +40,42 @@ function defaultFormatter(messages) {
return output.trim();
}

// load custom rles
function loadCustomRules(rulesdir) {
Copy link
Member

Choose a reason for hiding this comment

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

Could this function be replaced with a call to node-glob?

index.js Outdated
/* eslint-disable import/no-dynamic-require */ // --> OFF
filepath = path.resolve(filepath);
try {
var module = require(filepath);
Copy link
Member

Choose a reason for hiding this comment

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

Please change this line to const module = require(filepath); // eslint-disable-line import/no-dynamic-require. I also would use a different variable instead of module to prevent shadowing the global module variable. Maybe rule instead?

index.js Outdated
function lint(source, options, webpack, done) {
try {
if (options.customRules) {
options.customRules.forEach(rule => HTMLHint.addRule(rule));
}
if (options.rulesdir) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you camelcase this option to rulesDir instead?

index.js Outdated
@@ -80,7 +111,7 @@ function lint(source, options, webpack, done) {
emitter = webpack.emitWarning;
}

emitter(options.formatter(report));
emitter(new Error(options.formatter(report)));
Copy link
Member

Choose a reason for hiding this comment

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

I believe the tests are failing because this is now being emitted as an error. This shouldn't be the case, especially if emitting as a warning not an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On my dev machine all the tests are green. And I added this because of a warning in friendly-errors-webpack-plugin : "value string instead of error instance".
I do not understand why they are failing on Travis :/

Copy link
Member

Choose a reason for hiding this comment

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

aha, I realised what was going wrong, travis + my local dev envrionment uses the yarn.lock which has an older version of webpack in the dependencies. It seems like webpack introduced a breaking change between 2.2.1 and 2.4.1 that throws if you emit non errors. If you sync your branch with master the tests should start passing 😄

@Benoit-Vasseur
Copy link
Contributor Author

Thanks for the review. Il will try to do the changes tomorrow.

@Benoit-Vasseur
Copy link
Contributor Author

I made the changes.
However the tests are failing on Travis :/ I do not understand why (it works on my machine). Could you look at it ? Thanks.

index.js Outdated
const ruleOption = options[ruleObj.id]; // we can pass a value to the rule
ruleObj.rule(HTMLHint, ruleOption);
} catch (err) {
throw new Error(err.message);
Copy link
Member

Choose a reason for hiding this comment

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

Is this try catch necessary? By wrapping it like this you'll lose the stack trace etc

package.json Outdated
@@ -39,6 +40,7 @@
"devDependencies": {
"chai": "^3.5.0",
"codecov-lite": "^0.1.3",
"glob": "^7.1.1",
"mocha": "^3.0.2",
Copy link
Member

Choose a reason for hiding this comment

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

This should be a dependency, not a dev dependency (also make sure the yarn.lock file is updated)

@codecov-io
Copy link

codecov-io commented Apr 25, 2017

Codecov Report

Merging #7 into master will increase coverage by 1.09%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   88.05%   89.15%   +1.09%     
==========================================
  Files           1        1              
  Lines          67       83      +16     
==========================================
+ Hits           59       74      +15     
- Misses          8        9       +1
Impacted Files Coverage Δ
index.js 89.15% <93.75%> (+1.09%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update edbe992...03c185a. Read the comment docs.

@mattlewis92 mattlewis92 merged commit 4f33df4 into htmlhint:master Apr 25, 2017
@mattlewis92
Copy link
Member

Released as 1.2.0, thanks for the contribution! 💯

@Benoit-Vasseur
Copy link
Contributor Author

Great :)
Thanks for your help :)

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.

3 participants