Skip to content

Commit

Permalink
Do not use module.parent for resolving rule name (#188)
Browse files Browse the repository at this point in the history
`module.parent` is cached after the first `require` and this results in nearly
all rules having the URL to `assertion-arguments`.
  • Loading branch information
sudo-suhas authored and sindresorhus committed Feb 15, 2018
1 parent c9f332f commit c5903fd
Show file tree
Hide file tree
Showing 27 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion rules/assertion-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
},
schema
}
Expand Down
2 changes: 1 addition & 1 deletion rules/assertion-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl('assertion-message', '4211212daf1bfcfff3ebc5d4efdc4ba1a87acbf1')
url: util.getDocsUrl(__filename, '4211212daf1bfcfff3ebc5d4efdc4ba1a87acbf1')
},
schema,
deprecated: true
Expand Down
2 changes: 1 addition & 1 deletion rules/max-asserts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
},
schema
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-async-fn-without-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-cb-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-duplicate-modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-identical-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-ignored-test-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
},
schema
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-invalid-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-nested-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-only-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
},
fixable: 'code'
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-skip-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-skip-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
},
fixable: 'code'
}
Expand Down
2 changes: 1 addition & 1 deletion rules/no-statement-after-end.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-todo-implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-todo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/no-unknown-modifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/prefer-async-await.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/prefer-power-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/test-ended.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/test-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
},
schema
}
Expand Down
2 changes: 1 addition & 1 deletion rules/use-t-well.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/use-t.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/use-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
2 changes: 1 addition & 1 deletion rules/use-true-false.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = {
create,
meta: {
docs: {
url: util.getDocsUrl()
url: util.getDocsUrl(__filename)
}
}
};
6 changes: 3 additions & 3 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import pkg from '../package';

test('returns the URL of the a named rule\'s documentation', t => {
const url = `https://github.com/avajs/eslint-plugin-ava/blob/v${pkg.version}/docs/rules/foo.md`;
t.is(util.getDocsUrl('foo'), url);
t.is(util.getDocsUrl('foo.js'), url);
});

test('returns the URL of the a named rule\'s documentation at a commit hash', t => {
const url = 'https://github.com/avajs/eslint-plugin-ava/blob/bar/docs/rules/foo.md';
t.is(util.getDocsUrl('foo', 'bar'), url);
t.is(util.getDocsUrl('foo.js', 'bar'), url);
});

test('determines the rule name from the file', t => {
const url = `https://github.com/avajs/eslint-plugin-ava/blob/v${pkg.version}/docs/rules/util.md`;
t.is(util.getDocsUrl(), url);
t.is(util.getDocsUrl(__filename), url);
});
4 changes: 2 additions & 2 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ const repoUrl = 'https://github.com/avajs/eslint-plugin-ava';
* @param {String} ruleName The name of the rule to generate a URL for.
* @return {String} The URL of the rule's documentation.
*/
const getDocsUrl = (ruleName, commitHash) => {
ruleName = ruleName || path.basename(module.parent.filename, '.js');
const getDocsUrl = (filename, commitHash) => {
const ruleName = path.basename(filename, '.js');
commitHash = commitHash || `v${pkg.version}`;
return `${repoUrl}/blob/${commitHash}/docs/rules/${ruleName}.md`;
};
Expand Down

0 comments on commit c5903fd

Please sign in to comment.