diff --git a/lib/rules/no-broken-template.js b/lib/rules/no-broken-template.js index 086acb6..dfad431 100644 --- a/lib/rules/no-broken-template.js +++ b/lib/rules/no-broken-template.js @@ -5,7 +5,7 @@ const lexer = require('pug-lexer') -const { isReactPugReference, buildLocation } = require('../util/eslint') +const { isReactPugReference, buildLocation, docsUrl } = require('../util/eslint') const getTemplate = require('../util/getTemplate') //------------------------------------------------------------------------------ @@ -18,6 +18,7 @@ module.exports = { description: 'Disallow broken template', category: 'Possible Errors', recommended: true, + url: docsUrl('no-broken-template'), }, schema: [], }, diff --git a/lib/rules/no-interpolation.js b/lib/rules/no-interpolation.js index 810556e..5effd68 100644 --- a/lib/rules/no-interpolation.js +++ b/lib/rules/no-interpolation.js @@ -3,7 +3,7 @@ * @author Eugene Zhlobo */ -const { isReactPugReference, buildLocation } = require('../util/eslint') +const { isReactPugReference, buildLocation, docsUrl } = require('../util/eslint') //------------------------------------------------------------------------------ // Rule Definition @@ -15,6 +15,7 @@ module.exports = { description: 'Disallow JavaScript interpolation', category: 'Best Practices', recommended: true, + url: docsUrl('no-interpolation'), }, schema: [], }, diff --git a/lib/rules/no-undef.js b/lib/rules/no-undef.js index c34ce8b..6c434bc 100644 --- a/lib/rules/no-undef.js +++ b/lib/rules/no-undef.js @@ -3,7 +3,7 @@ * @author Eugene Zhlobo */ -const { isReactPugReference, buildLocation } = require('../util/eslint') +const { isReactPugReference, buildLocation, docsUrl } = require('../util/eslint') const getTemplate = require('../util/getTemplate') const getVariables = require('../util/getVariables') @@ -17,6 +17,7 @@ module.exports = { description: 'Disallow undeclared variables in Pug', category: 'Possible Errors', recommended: true, + url: docsUrl('no-undef'), }, schema: [], }, diff --git a/lib/rules/quotes.js b/lib/rules/quotes.js index 45dc150..747d341 100644 --- a/lib/rules/quotes.js +++ b/lib/rules/quotes.js @@ -6,7 +6,7 @@ const { parse } = require('@babel/parser') const codeWalk = require('@babel/traverse').default -const { isReactPugReference, buildLocation } = require('../util/eslint') +const { isReactPugReference, buildLocation, docsUrl } = require('../util/eslint') const getTemplate = require('../util/getTemplate') const getTokens = require('../util/getTokens') @@ -33,6 +33,7 @@ module.exports = { description: 'Manage quotes in Pug', category: 'Best Practices', recommended: true, + url: docsUrl('quotes'), }, schema: [], }, diff --git a/lib/rules/uses-react.js b/lib/rules/uses-react.js index f708862..441c0b0 100644 --- a/lib/rules/uses-react.js +++ b/lib/rules/uses-react.js @@ -3,7 +3,7 @@ * @author Eugene Zhlobo */ -const { isReactPugReference } = require('../util/eslint') +const { isReactPugReference, docsUrl } = require('../util/eslint') //------------------------------------------------------------------------------ // Rule Definition @@ -15,6 +15,7 @@ module.exports = { description: 'Prevent React to be marked as unused', category: 'Best Practices', recommended: true, + url: docsUrl('uses-react'), }, schema: [], }, diff --git a/lib/rules/uses-vars.js b/lib/rules/uses-vars.js index 4e72a71..fe09eb4 100644 --- a/lib/rules/uses-vars.js +++ b/lib/rules/uses-vars.js @@ -3,7 +3,7 @@ * @author Eugene Zhlobo */ -const { isReactPugReference } = require('../util/eslint') +const { isReactPugReference, docsUrl } = require('../util/eslint') const getTemplate = require('../util/getTemplate') const getVariables = require('../util/getVariables') @@ -17,6 +17,7 @@ module.exports = { description: 'Prevent variables used in Pug to be marked as unused', category: 'Best Practices', recommended: true, + url: docsUrl('uses-vars'), }, schema: [], }, diff --git a/lib/util/eslint.js b/lib/util/eslint.js index 35b3362..3665311 100644 --- a/lib/util/eslint.js +++ b/lib/util/eslint.js @@ -1,3 +1,7 @@ +function docsUrl(ruleName) { + return `https://github.com/ezhlobo/eslint-plugin-react-pug/blob/master/docs/rules/${ruleName}.md` +} + function buildLocation(startCoord, endCoord) { return { start: { @@ -16,6 +20,7 @@ function isReactPugReference({ tag }) { } module.exports = { + docsUrl, buildLocation, isReactPugReference, diff --git a/tests/each-rule.js b/tests/each-rule.js new file mode 100644 index 0000000..899cd61 --- /dev/null +++ b/tests/each-rule.js @@ -0,0 +1,21 @@ +const assert = require('assert') +const fs = require('fs') +const path = require('path') + +const { docsUrl } = require('../lib/util/eslint') + +const ruleFiles = fs.readdirSync(path.resolve(__dirname, '..', 'lib', 'rules')) + .map(file => path.basename(file, '.js')) + +describe('URLs to documentation', () => { + ruleFiles.forEach((ruleName) => { + it(ruleName, () => { + const filepath = path.resolve(__dirname, '..', 'lib', 'rules', `${ruleName}.js`) + + // eslint-disable-next-line global-require, import/no-dynamic-require + const file = require(filepath) + + assert.equal(file.meta.docs.url, docsUrl(ruleName)) + }) + }) +}) diff --git a/tests/lib/rules/no-undef.js b/tests/lib/rules/no-undef.js index 1405dd5..802d852 100644 --- a/tests/lib/rules/no-undef.js +++ b/tests/lib/rules/no-undef.js @@ -17,9 +17,6 @@ const rule = require('../../../lib/rules/no-undef') const parserOptions = { ecmaVersion: 8, sourceType: 'module', - ecmaFeatures: { - experimentalObjectRestSpread: true, - }, } //------------------------------------------------------------------------------ diff --git a/tests/lib/rules/quotes.js b/tests/lib/rules/quotes.js index 234d837..49d0700 100644 --- a/tests/lib/rules/quotes.js +++ b/tests/lib/rules/quotes.js @@ -16,9 +16,6 @@ const rule = require('../../../lib/rules/quotes') const parserOptions = { ecmaVersion: 8, sourceType: 'module', - ecmaFeatures: { - experimentalObjectRestSpread: true, - }, } //------------------------------------------------------------------------------ diff --git a/tests/lib/rules/uses-react.js b/tests/lib/rules/uses-react.js index 887d48b..a07620b 100644 --- a/tests/lib/rules/uses-react.js +++ b/tests/lib/rules/uses-react.js @@ -17,9 +17,6 @@ const rule = require('../../../lib/rules/uses-react') const parserOptions = { ecmaVersion: 8, sourceType: 'module', - ecmaFeatures: { - experimentalObjectRestSpread: true, - }, } //------------------------------------------------------------------------------ diff --git a/tests/lib/rules/uses-vars.js b/tests/lib/rules/uses-vars.js index 0ccf38b..91256b5 100644 --- a/tests/lib/rules/uses-vars.js +++ b/tests/lib/rules/uses-vars.js @@ -18,9 +18,6 @@ const rule = require('../../../lib/rules/uses-vars') const parserOptions = { ecmaVersion: 8, sourceType: 'module', - ecmaFeatures: { - experimentalObjectRestSpread: true, - }, } //------------------------------------------------------------------------------