Skip to content

Commit

Permalink
docs: Use link to tagged version for rule docs (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-suhas authored and macklinu committed Feb 21, 2018
1 parent c0c662a commit 8c82ddb
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 23 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
"prefer-const": "error",
"strict": ["error", "global"],
"eslint-plugin/prefer-placeholders": "error",
"eslint-plugin/require-meta-docs-url": [
"error",
{
"pattern": "https://github.com/xjamundx/eslint-plugin-promise#{{name}}"
}
],
"eslint-plugin/test-case-shorthand-strings": "error",
"node/no-unsupported-features": ["error", { "version": 4 }],
"prettier/prettier": "error"
Expand Down
4 changes: 3 additions & 1 deletion rules/always-return.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const getDocsUrl = require('./lib/get-docs-url')

function isFunctionWithBlockStatement(node) {
if (node.type === 'FunctionExpression') {
return true
Expand Down Expand Up @@ -55,7 +57,7 @@ function peek(arr) {
module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#always-return'
url: getDocsUrl('always-return')
}
},
create: function(context) {
Expand Down
4 changes: 3 additions & 1 deletion rules/avoid-new.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')

module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#avoid-new'
url: getDocsUrl('avoid-new')
}
},
create: function(context) {
Expand Down
3 changes: 2 additions & 1 deletion rules/catch-or-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const isPromise = require('./lib/is-promise')

module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#catch-or-return'
url: getDocsUrl('catch-or-return')
}
},
create: function(context) {
Expand Down
19 changes: 19 additions & 0 deletions rules/lib/get-docs-url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const pkg = require('../../package')

const REPO_URL = 'https://github.com/xjamundx/eslint-plugin-promise'

/**
* Generates the URL to documentation for the given rule name. It uses the
* package version to build the link to a tagged version of the
* documentation file.
*
* @param {string} ruleName - Name of the eslint rule
* @returns {string} URL to the documentation for the given rule
*/
function getDocsUrl(ruleName) {
return `${REPO_URL}/tree/v${pkg.version}#${ruleName}`
}

module.exports = getDocsUrl
4 changes: 2 additions & 2 deletions rules/no-callback-in-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const hasPromiseCallback = require('./lib/has-promise-callback')
const isInsidePromise = require('./lib/is-inside-promise')
const isCallback = require('./lib/is-callback')

module.exports = {
meta: {
docs: {
url:
'https://github.com/xjamundx/eslint-plugin-promise#no-callback-in-promise'
url: getDocsUrl('no-callback-in-promise')
}
},
create: function(context) {
Expand Down
4 changes: 3 additions & 1 deletion rules/no-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')

function isDeclared(scope, ref) {
return scope.variables.some(function(variable) {
if (variable.name !== ref.identifier.name) {
Expand All @@ -20,7 +22,7 @@ function isDeclared(scope, ref) {
module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#no-native'
url: getDocsUrl('no-native')
}
},
create: function(context) {
Expand Down
3 changes: 2 additions & 1 deletion rules/no-nesting.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const hasPromiseCallback = require('./lib/has-promise-callback')
const isInsidePromise = require('./lib/is-inside-promise')

module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#no-nesting'
url: getDocsUrl('no-nesting')
}
},
create: function(context) {
Expand Down
4 changes: 2 additions & 2 deletions rules/no-promise-in-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const isPromise = require('./lib/is-promise')
const isInsideCallback = require('./lib/is-inside-callback')

module.exports = {
meta: {
docs: {
url:
'https://github.com/xjamundx/eslint-plugin-promise#no-promise-in-callback'
url: getDocsUrl('no-promise-in-callback')
}
},
create: function(context) {
Expand Down
4 changes: 2 additions & 2 deletions rules/no-return-in-finally.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const isPromise = require('./lib/is-promise')

module.exports = {
meta: {
docs: {
url:
'https://github.com/xjamundx/eslint-plugin-promise#no-return-in-finally'
url: getDocsUrl('no-return-in-finally')
}
},
create: function(context) {
Expand Down
3 changes: 2 additions & 1 deletion rules/no-return-wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')
const isPromise = require('./lib/is-promise')
const rejectMessage = 'Expected throw instead of Promise.reject'
const resolveMessage = 'Avoid wrapping return values in Promise.resolve'
Expand All @@ -20,7 +21,7 @@ function isInPromise(context) {
module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#no-return-wrap'
url: getDocsUrl('no-return-wrap')
}
},
create: function(context) {
Expand Down
4 changes: 3 additions & 1 deletion rules/param-names.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

const getDocsUrl = require('./lib/get-docs-url')

module.exports = {
meta: {
docs: {
url: 'https://github.com/xjamundx/eslint-plugin-promise#param-names'
url: getDocsUrl('param-names')
},
fixable: 'code'
},
Expand Down
5 changes: 3 additions & 2 deletions rules/prefer-await-to-callbacks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')

const errorMessage = 'Avoid callbacks. Prefer Async/Await.'

module.exports = {
meta: {
docs: {
url:
'https://github.com/xjamundx/eslint-plugin-promise#prefer-await-to-callbacks'
url: getDocsUrl('prefer-await-to-callbacks')
}
},
create: function(context) {
Expand Down
5 changes: 3 additions & 2 deletions rules/prefer-await-to-then.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@

'use strict'

const getDocsUrl = require('./lib/get-docs-url')

module.exports = {
meta: {
docs: {
url:
'https://github.com/xjamundx/eslint-plugin-promise#prefer-await-to-then'
url: getDocsUrl('prefer-await-to-then')
}
},
create: function(context) {
Expand Down

0 comments on commit 8c82ddb

Please sign in to comment.