Skip to content

Commit

Permalink
Add no-interpolation rule to README and write tests that all rules ar…
Browse files Browse the repository at this point in the history
…e mentioned there
  • Loading branch information
ezhlobo committed Aug 23, 2018
1 parent 5019c1c commit 535e7b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 28 additions & 7 deletions tests/each-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
})
})

0 comments on commit 535e7b1

Please sign in to comment.