Skip to content

Commit

Permalink
Set URLs to documentation for each rule (#34)
Browse files Browse the repository at this point in the history
Close #32 

Now each rule is linked to documentation page, so users can get necessary information from convenient place.
  • Loading branch information
ezhlobo authored Aug 23, 2018
1 parent d8a15bc commit 5019c1c
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lib/rules/no-broken-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

//------------------------------------------------------------------------------
Expand All @@ -18,6 +18,7 @@ module.exports = {
description: 'Disallow broken template',
category: 'Possible Errors',
recommended: true,
url: docsUrl('no-broken-template'),
},
schema: [],
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-interpolation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Eugene Zhlobo
*/

const { isReactPugReference, buildLocation } = require('../util/eslint')
const { isReactPugReference, buildLocation, docsUrl } = require('../util/eslint')

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -15,6 +15,7 @@ module.exports = {
description: 'Disallow JavaScript interpolation',
category: 'Best Practices',
recommended: true,
url: docsUrl('no-interpolation'),
},
schema: [],
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -17,6 +17,7 @@ module.exports = {
description: 'Disallow undeclared variables in Pug',
category: 'Possible Errors',
recommended: true,
url: docsUrl('no-undef'),
},
schema: [],
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -33,6 +33,7 @@ module.exports = {
description: 'Manage quotes in Pug',
category: 'Best Practices',
recommended: true,
url: docsUrl('quotes'),
},
schema: [],
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/uses-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @author Eugene Zhlobo
*/

const { isReactPugReference } = require('../util/eslint')
const { isReactPugReference, docsUrl } = require('../util/eslint')

//------------------------------------------------------------------------------
// Rule Definition
Expand All @@ -15,6 +15,7 @@ module.exports = {
description: 'Prevent React to be marked as unused',
category: 'Best Practices',
recommended: true,
url: docsUrl('uses-react'),
},
schema: [],
},
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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: [],
},
Expand Down
5 changes: 5 additions & 0 deletions lib/util/eslint.js
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -16,6 +20,7 @@ function isReactPugReference({ tag }) {
}

module.exports = {
docsUrl,
buildLocation,

isReactPugReference,
Expand Down
21 changes: 21 additions & 0 deletions tests/each-rule.js
Original file line number Diff line number Diff line change
@@ -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))
})
})
})
3 changes: 0 additions & 3 deletions tests/lib/rules/no-undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const rule = require('../../../lib/rules/no-undef')
const parserOptions = {
ecmaVersion: 8,
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions tests/lib/rules/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ const rule = require('../../../lib/rules/quotes')
const parserOptions = {
ecmaVersion: 8,
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions tests/lib/rules/uses-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const rule = require('../../../lib/rules/uses-react')
const parserOptions = {
ecmaVersion: 8,
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
}

//------------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions tests/lib/rules/uses-vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ const rule = require('../../../lib/rules/uses-vars')
const parserOptions = {
ecmaVersion: 8,
sourceType: 'module',
ecmaFeatures: {
experimentalObjectRestSpread: true,
},
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 5019c1c

Please sign in to comment.