Skip to content

Commit 6e79636

Browse files
ranyitzSimenB
authored andcommittedMar 3, 2018
fix(util): add a test instead of throwing an error on getDocsUrl (#96)
fixes #91
1 parent 7ca76fa commit 6e79636

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed
 

‎__tests__/rules.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const path = require('path');
5+
const rules = require('../index').rules;
6+
7+
describe('rules', () => {
8+
it('should have a corresponding doc for each rule', () => {
9+
Object.keys(rules).forEach(rule => {
10+
const docPath = path.resolve(__dirname, '../docs/rules', `${rule}.md`);
11+
12+
if (!fs.existsSync(docPath)) {
13+
throw new Error(
14+
`Could not find documentation file for rule "${rule}" in path "${docPath}"`
15+
);
16+
}
17+
});
18+
});
19+
});

‎rules/util.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
'use strict';
22

3-
const fs = require('fs');
43
const path = require('path');
5-
const pkg = require('../package.json');
4+
const version = require('../package.json').version;
65

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

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

131-
const docsFile = path.join(__dirname, `../docs/rules/${ruleName}.md`);
132-
// istanbul ignore if
133-
if (!fs.existsSync(docsFile)) {
134-
throw new Error(`Could not find documentation file for rule "${ruleName}"`);
135-
}
136-
137-
return `${REPO_URL}/blob/v${pkg.version}/docs/rules/${ruleName}.md`;
129+
return `${REPO_URL}/blob/v${version}/docs/rules/${ruleName}.md`;
138130
};
139131

140132
module.exports = {

0 commit comments

Comments
 (0)