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

fix(util): add a test instead of throwing an error on getDocsUrl #96

Merged
merged 2 commits into from
Mar 3, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions __tests__/rules.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

const fs = require('fs');
const path = require('path');
const rules = require('../index').rules;

describe('rules', () => {
it('should have a corresponding doc for each rule', () => {
Object.keys(rules).forEach(rule => {
const docPath = path.resolve(__dirname, '../docs/rules', `${rule}.md`);

if (!fs.existsSync(docPath)) {
throw new Error(
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
);
}
});
});
});
12 changes: 2 additions & 10 deletions rules/util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

const fs = require('fs');
const path = require('path');
const pkg = require('../package.json');
const version = require('../package.json').version;

const REPO_URL = 'https://github.com/jest-community/eslint-plugin-jest';

Expand Down Expand Up @@ -123,18 +122,11 @@ const isFunction = node =>
*
* @param {string} filename - Name of the eslint rule
* @returns {string} URL to the documentation for the given rule
* @throws {Error} If the documentation file for the given rule is not present.
*/
const getDocsUrl = filename => {
const ruleName = path.basename(filename, '.js');

const docsFile = path.join(__dirname, `../docs/rules/${ruleName}.md`);
// istanbul ignore if
if (!fs.existsSync(docsFile)) {
throw new Error(`Could not find documentation file for rule "${ruleName}"`);
}

return `${REPO_URL}/blob/v${pkg.version}/docs/rules/${ruleName}.md`;
return `${REPO_URL}/blob/v${version}/docs/rules/${ruleName}.md`;
};

module.exports = {
Expand Down