diff --git a/__tests__/rules.test.js b/__tests__/rules.test.js new file mode 100644 index 000000000..ffc054422 --- /dev/null +++ b/__tests__/rules.test.js @@ -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}"` + ); + } + }); + }); +}); diff --git a/rules/util.js b/rules/util.js index 933eb4bd1..2dd9def8b 100644 --- a/rules/util.js +++ b/rules/util.js @@ -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'; @@ -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 = {