From 7f54220417a7a578a96b08055a624099582ba368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Wed, 31 Mar 2021 15:30:45 +0100 Subject: [PATCH 1/2] Add info into the `meta` property of rules --- lib/rules/array-foreach.js | 6 +++- lib/rules/async-currenttarget.js | 6 +++- lib/rules/async-preventdefault.js | 6 +++- lib/rules/authenticity-token.js | 6 +++- lib/rules/get-attribute.js | 9 ++++++ lib/rules/js-class-name.js | 6 +++- lib/rules/no-blur.js | 10 +++++-- lib/rules/no-d-none.js | 8 ++++++ lib/rules/no-dataset.js | 6 +++- lib/rules/no-implicit-buggy-globals.js | 6 +++- lib/rules/no-innerText.js | 9 ++++-- lib/rules/no-then.js | 7 ++++- lib/rules/no-useless-passive.js | 9 ++++-- lib/rules/prefer-observers.js | 8 ++++-- lib/rules/require-passive-events.js | 7 ++++- lib/rules/unescaped-html-literal.js | 39 +++++++++++++++++--------- 16 files changed, 117 insertions(+), 31 deletions(-) diff --git a/lib/rules/array-foreach.js b/lib/rules/array-foreach.js index 7b5aee96..2585e746 100644 --- a/lib/rules/array-foreach.js +++ b/lib/rules/array-foreach.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'suggestion', + docs: { + description: 'enforce `for..of` loops over `Array.forEach`', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/array-foreach.md' + }, schema: [] }, diff --git a/lib/rules/async-currenttarget.js b/lib/rules/async-currenttarget.js index d07605ef..e5794e88 100644 --- a/lib/rules/async-currenttarget.js +++ b/lib/rules/async-currenttarget.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'problem', + docs: { + description: 'disallow `event.currentTarget` calls inside of async functions', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-currenttarget.md' + }, schema: [] }, diff --git a/lib/rules/async-preventdefault.js b/lib/rules/async-preventdefault.js index ab996c49..808c65b7 100644 --- a/lib/rules/async-preventdefault.js +++ b/lib/rules/async-preventdefault.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'problem', + docs: { + description: 'disallow `event.preventDefault` calls inside of async functions', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventDefault.md' + }, schema: [] }, diff --git a/lib/rules/authenticity-token.js b/lib/rules/authenticity-token.js index bccc678d..3621fecf 100644 --- a/lib/rules/authenticity-token.js +++ b/lib/rules/authenticity-token.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'problem', + docs: { + description: 'disallow usage of CSRF tokens in JavaScript', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/authenticity-token.md' + }, schema: [] }, diff --git a/lib/rules/get-attribute.js b/lib/rules/get-attribute.js index 27eb873b..26900203 100644 --- a/lib/rules/get-attribute.js +++ b/lib/rules/get-attribute.js @@ -19,6 +19,15 @@ function isValidAttribute(name) { module.exports = function(context) { return { + meta: { + type: 'problem', + docs: { + description: 'disallow wrong usage of attribute names', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/get-attribute.md' + }, + fixable: 'code', + schema: [] + }, CallExpression(node) { if (!node.callee.property) return diff --git a/lib/rules/js-class-name.js b/lib/rules/js-class-name.js index e2f2a6c5..9494a212 100644 --- a/lib/rules/js-class-name.js +++ b/lib/rules/js-class-name.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'suggestion', + docs: { + description: 'enforce a naming convention for js- prefixed classes', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/js-class-name.md' + }, schema: [] }, diff --git a/lib/rules/no-blur.js b/lib/rules/no-blur.js index 59b21642..c2c6ec14 100644 --- a/lib/rules/no-blur.js +++ b/lib/rules/no-blur.js @@ -1,5 +1,13 @@ module.exports = function(context) { return { + meta: { + type: 'problem', + docs: { + description: 'disallow usage of `Element.prototype.blur()`', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-blur.md' + }, + schema: [] + }, CallExpression(node) { if (node.callee.property && node.callee.property.name === 'blur') { context.report(node, 'Do not use element.blur(), instead restore the focus of a previous element.') @@ -7,5 +15,3 @@ module.exports = function(context) { } } } - -module.exports.schema = [] diff --git a/lib/rules/no-d-none.js b/lib/rules/no-d-none.js index a742fa18..e0bc39e8 100644 --- a/lib/rules/no-d-none.js +++ b/lib/rules/no-d-none.js @@ -1,4 +1,12 @@ module.exports = { + meta: { + type: 'problem', + docs: { + description: 'disallow usage the `d-none` CSS class', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-d-none.md' + }, + schema: [] + }, create(context) { return { CallExpression(node) { diff --git a/lib/rules/no-dataset.js b/lib/rules/no-dataset.js index d43aad81..16365b4f 100644 --- a/lib/rules/no-dataset.js +++ b/lib/rules/no-dataset.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'problem', + docs: { + description: 'enforce usage of `Element.prototype.getAttribute` instead of `Element.prototype.datalist`', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-dataset.md' + }, schema: [] }, diff --git a/lib/rules/no-implicit-buggy-globals.js b/lib/rules/no-implicit-buggy-globals.js index 66348812..fed703e1 100644 --- a/lib/rules/no-implicit-buggy-globals.js +++ b/lib/rules/no-implicit-buggy-globals.js @@ -1,6 +1,10 @@ module.exports = { meta: { - docs: {}, + type: 'problem', + docs: { + description: 'disallow implicit global variables', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-implicit-buggy-globals.md' + }, schema: [] }, diff --git a/lib/rules/no-innerText.js b/lib/rules/no-innerText.js index c6bf056b..7c73e8cb 100644 --- a/lib/rules/no-innerText.js +++ b/lib/rules/no-innerText.js @@ -1,7 +1,12 @@ module.exports = { meta: { - docs: {}, - fixable: 'code' + type: 'problem', + docs: { + description: 'disallow `Element.prototype.innerText` in favor of `Element.prototype.textContent`', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-innerText.md' + }, + fixable: 'code', + schema: [] }, create(context) { diff --git a/lib/rules/no-then.js b/lib/rules/no-then.js index 0f152b8c..eede41d3 100644 --- a/lib/rules/no-then.js +++ b/lib/rules/no-then.js @@ -1,6 +1,11 @@ module.exports = { meta: { - docs: {} + type: 'suggestion', + docs: { + description: 'enforce using `async/await` syntax over Promises', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-then.md' + }, + schema: [] }, create(context) { diff --git a/lib/rules/no-useless-passive.js b/lib/rules/no-useless-passive.js index f9eef57d..6495e260 100644 --- a/lib/rules/no-useless-passive.js +++ b/lib/rules/no-useless-passive.js @@ -4,8 +4,13 @@ const propIsPassiveTrue = prop => prop.key && prop.key.name === 'passive' && pro module.exports = { meta: { - docs: {}, - fixable: 'code' + type: 'suggestion', + docs: { + description: 'disallow marking a event handler as passive when it has no effect', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-useless-passive.md' + }, + fixable: 'code', + schema: [] }, create(context) { diff --git a/lib/rules/prefer-observers.js b/lib/rules/prefer-observers.js index 0e9824a6..f7548da7 100644 --- a/lib/rules/prefer-observers.js +++ b/lib/rules/prefer-observers.js @@ -4,8 +4,12 @@ const observerMap = { } module.exports = { meta: { - docs: {}, - fixable: 'code' + type: 'suggestion', + docs: { + description: 'disallow poorly performing event listeners', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/prefer-observers.md' + }, + schema: [] }, create(context) { diff --git a/lib/rules/require-passive-events.js b/lib/rules/require-passive-events.js index 72b8a682..d203e3c1 100644 --- a/lib/rules/require-passive-events.js +++ b/lib/rules/require-passive-events.js @@ -4,7 +4,12 @@ const propIsPassiveTrue = prop => prop.key && prop.key.name === 'passive' && pro module.exports = { meta: { - docs: {} + type: 'suggestion', + docs: { + description: 'enforce marking high frequency event handlers as passive', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/require-passive-events.md' + }, + schema: [] }, create(context) { diff --git a/lib/rules/unescaped-html-literal.js b/lib/rules/unescaped-html-literal.js index fc4f6f40..5eb52654 100644 --- a/lib/rules/unescaped-html-literal.js +++ b/lib/rules/unescaped-html-literal.js @@ -1,24 +1,35 @@ -module.exports = function(context) { - const htmlOpenTag = /^<[a-zA-Z]/ - const message = 'Unescaped HTML literal. Use html`` tag template literal for secure escaping.' +module.exports = { + meta: { + type: 'problem', + docs: { + description: 'disallow unesaped HTML literals', + url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/unescaped-html-literal.md' + }, + schema: [] + }, - return { - Literal(node) { - if (!htmlOpenTag.test(node.value)) return + create(context) { + const htmlOpenTag = /^<[a-zA-Z]/ + const message = 'Unescaped HTML literal. Use html`` tag template literal for secure escaping.' - context.report({ - node, - message - }) - }, - TemplateLiteral(node) { - if (!htmlOpenTag.test(node.quasis[0].value.raw)) return + return { + Literal(node) { + if (!htmlOpenTag.test(node.value)) return - if (!node.parent.tag || node.parent.tag.name !== 'html') { context.report({ node, message }) + }, + TemplateLiteral(node) { + if (!htmlOpenTag.test(node.quasis[0].value.raw)) return + + if (!node.parent.tag || node.parent.tag.name !== 'html') { + context.report({ + node, + message + }) + } } } } From 5e2959dd0f861c7d6e233628b407e10cb684764f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Oddsson?= Date: Wed, 31 Mar 2021 16:33:52 +0100 Subject: [PATCH 2/2] Set `url` parameter automatically --- lib/rules/array-foreach.js | 2 +- lib/rules/async-currenttarget.js | 2 +- lib/rules/async-preventdefault.js | 2 +- lib/rules/authenticity-token.js | 2 +- lib/rules/get-attribute.js | 2 +- lib/rules/js-class-name.js | 2 +- lib/rules/no-blur.js | 2 +- lib/rules/no-d-none.js | 2 +- lib/rules/no-dataset.js | 2 +- lib/rules/no-implicit-buggy-globals.js | 2 +- lib/rules/no-innerText.js | 2 +- lib/rules/no-then.js | 2 +- lib/rules/no-useless-passive.js | 2 +- lib/rules/prefer-observers.js | 2 +- lib/rules/require-passive-events.js | 2 +- lib/rules/unescaped-html-literal.js | 2 +- lib/url.js | 9 +++++++++ 17 files changed, 25 insertions(+), 16 deletions(-) create mode 100644 lib/url.js diff --git a/lib/rules/array-foreach.js b/lib/rules/array-foreach.js index 2585e746..f7e7a55f 100644 --- a/lib/rules/array-foreach.js +++ b/lib/rules/array-foreach.js @@ -3,7 +3,7 @@ module.exports = { type: 'suggestion', docs: { description: 'enforce `for..of` loops over `Array.forEach`', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/array-foreach.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/async-currenttarget.js b/lib/rules/async-currenttarget.js index e5794e88..40c4f98f 100644 --- a/lib/rules/async-currenttarget.js +++ b/lib/rules/async-currenttarget.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow `event.currentTarget` calls inside of async functions', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-currenttarget.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/async-preventdefault.js b/lib/rules/async-preventdefault.js index 808c65b7..fa05ccd9 100644 --- a/lib/rules/async-preventdefault.js +++ b/lib/rules/async-preventdefault.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow `event.preventDefault` calls inside of async functions', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/async-preventDefault.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/authenticity-token.js b/lib/rules/authenticity-token.js index 3621fecf..43a0da44 100644 --- a/lib/rules/authenticity-token.js +++ b/lib/rules/authenticity-token.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow usage of CSRF tokens in JavaScript', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/authenticity-token.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/get-attribute.js b/lib/rules/get-attribute.js index 26900203..c30594b1 100644 --- a/lib/rules/get-attribute.js +++ b/lib/rules/get-attribute.js @@ -23,7 +23,7 @@ module.exports = function(context) { type: 'problem', docs: { description: 'disallow wrong usage of attribute names', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/get-attribute.md' + url: require('../url')(module) }, fixable: 'code', schema: [] diff --git a/lib/rules/js-class-name.js b/lib/rules/js-class-name.js index 9494a212..78a3b273 100644 --- a/lib/rules/js-class-name.js +++ b/lib/rules/js-class-name.js @@ -3,7 +3,7 @@ module.exports = { type: 'suggestion', docs: { description: 'enforce a naming convention for js- prefixed classes', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/js-class-name.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/no-blur.js b/lib/rules/no-blur.js index c2c6ec14..ad336b05 100644 --- a/lib/rules/no-blur.js +++ b/lib/rules/no-blur.js @@ -4,7 +4,7 @@ module.exports = function(context) { type: 'problem', docs: { description: 'disallow usage of `Element.prototype.blur()`', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-blur.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/no-d-none.js b/lib/rules/no-d-none.js index e0bc39e8..7513f2e1 100644 --- a/lib/rules/no-d-none.js +++ b/lib/rules/no-d-none.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow usage the `d-none` CSS class', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-d-none.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/no-dataset.js b/lib/rules/no-dataset.js index 16365b4f..5f7b5ede 100644 --- a/lib/rules/no-dataset.js +++ b/lib/rules/no-dataset.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'enforce usage of `Element.prototype.getAttribute` instead of `Element.prototype.datalist`', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-dataset.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/no-implicit-buggy-globals.js b/lib/rules/no-implicit-buggy-globals.js index fed703e1..39992213 100644 --- a/lib/rules/no-implicit-buggy-globals.js +++ b/lib/rules/no-implicit-buggy-globals.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow implicit global variables', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-implicit-buggy-globals.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/no-innerText.js b/lib/rules/no-innerText.js index 7c73e8cb..b1396d77 100644 --- a/lib/rules/no-innerText.js +++ b/lib/rules/no-innerText.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow `Element.prototype.innerText` in favor of `Element.prototype.textContent`', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-innerText.md' + url: require('../url')(module) }, fixable: 'code', schema: [] diff --git a/lib/rules/no-then.js b/lib/rules/no-then.js index eede41d3..f53517f4 100644 --- a/lib/rules/no-then.js +++ b/lib/rules/no-then.js @@ -3,7 +3,7 @@ module.exports = { type: 'suggestion', docs: { description: 'enforce using `async/await` syntax over Promises', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-then.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/no-useless-passive.js b/lib/rules/no-useless-passive.js index 6495e260..ab6a685f 100644 --- a/lib/rules/no-useless-passive.js +++ b/lib/rules/no-useless-passive.js @@ -7,7 +7,7 @@ module.exports = { type: 'suggestion', docs: { description: 'disallow marking a event handler as passive when it has no effect', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/no-useless-passive.md' + url: require('../url')(module) }, fixable: 'code', schema: [] diff --git a/lib/rules/prefer-observers.js b/lib/rules/prefer-observers.js index f7548da7..87280f34 100644 --- a/lib/rules/prefer-observers.js +++ b/lib/rules/prefer-observers.js @@ -7,7 +7,7 @@ module.exports = { type: 'suggestion', docs: { description: 'disallow poorly performing event listeners', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/prefer-observers.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/require-passive-events.js b/lib/rules/require-passive-events.js index d203e3c1..9b05a4f0 100644 --- a/lib/rules/require-passive-events.js +++ b/lib/rules/require-passive-events.js @@ -7,7 +7,7 @@ module.exports = { type: 'suggestion', docs: { description: 'enforce marking high frequency event handlers as passive', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/require-passive-events.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/rules/unescaped-html-literal.js b/lib/rules/unescaped-html-literal.js index 5eb52654..51f59372 100644 --- a/lib/rules/unescaped-html-literal.js +++ b/lib/rules/unescaped-html-literal.js @@ -3,7 +3,7 @@ module.exports = { type: 'problem', docs: { description: 'disallow unesaped HTML literals', - url: 'https://github.com/github/eslint-plugin-github/blob/main/docs/rules/unescaped-html-literal.md' + url: require('../url')(module) }, schema: [] }, diff --git a/lib/url.js b/lib/url.js new file mode 100644 index 00000000..30e162e1 --- /dev/null +++ b/lib/url.js @@ -0,0 +1,9 @@ +const {homepage, version} = require('../package.json') +const path = require('path') +module.exports = ({id}) => { + const url = new URL(homepage) + const rule = path.basename(id, '.js') + url.hash = '' + url.pathname += `/blob/v${version}/docs/rules/${rule}.md` + return url.toString() +}