From 535e7b1ff7d2514bc0b5af4899d2aeb6dd12d61b Mon Sep 17 00:00:00 2001 From: Eugene Zhlobo Date: Thu, 23 Aug 2018 09:14:40 +0300 Subject: [PATCH] Add no-interpolation rule to README and write tests that all rules are mentioned there --- README.md | 1 + tests/each-rule.js | 35 ++++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 335c9fb..0b05d3d 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Then configure the rules you want to use under the rules section. ## List of supported rules * [`react-pug/no-broken-template`](./docs/rules/no-broken-template.md): Disallow broken template +* [`react-pug/no-interpolation`](./docs/rules/no-interpolation.md): Disallow JavaScript interpolation * [`react-pug/no-undef`](./docs/rules/no-undef.md): Disallow undeclared variables in Pug * [`react-pug/quotes`](./docs/rules/quotes.md): Manage quotes in Pug * [`react-pug/uses-react`](./docs/rules/uses-react.md): Prevent React to be marked as unused diff --git a/tests/each-rule.js b/tests/each-rule.js index 899cd61..a24bf9a 100644 --- a/tests/each-rule.js +++ b/tests/each-rule.js @@ -7,15 +7,36 @@ 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`) +describe('each rule', () => { + describe('has url 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) + // eslint-disable-next-line global-require, import/no-dynamic-require + const file = require(filepath) - assert.equal(file.meta.docs.url, docsUrl(ruleName)) + assert.equal(file.meta.docs.url, docsUrl(ruleName)) + }) + }) + }) + + describe('mentioned in README', () => { + const listOfRulesInReadme = fs + .readFileSync(path.resolve(__dirname, '..', 'README.md'), 'utf-8') + .match(/## List of supported rules\n+((\*.+\n+)+)/m)[1] + .split('\n') + .filter(Boolean) + + ruleFiles.forEach((ruleName) => { + it(ruleName, () => { + const checker = new RegExp(`^\\* \\[\`react-pug/${ruleName}\`\\]\\(\\./docs/rules/${ruleName}.md\\): .+$`) + + const isPresented = listOfRulesInReadme + .find(item => checker.test(item)) + + assert(isPresented) + }) }) }) })