Skip to content

Commit

Permalink
fix(util): add a test instead of throwing an error on getDocsUrl (#96)
Browse files Browse the repository at this point in the history
fixes #91
  • Loading branch information
ranyitz authored and SimenB committed Mar 3, 2018
1 parent 7ca76fa commit 6e79636
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
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

0 comments on commit 6e79636

Please # to comment.