Skip to content

Commit

Permalink
Merge branch 'main' into set-correct-meta-info-on-rules
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Apr 1, 2021
2 parents 5e2959d + 25c29a0 commit bc687f5
Show file tree
Hide file tree
Showing 10 changed files with 3,970 additions and 1,104 deletions.
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# eslint-plugin-github

[![Node CI](https://github.com/github/eslint-plugin-github/actions/workflows/nodejs.yml/badge.svg)](https://github.com/github/eslint-plugin-github/actions/workflows/nodejs.yml)

## Installation

```sh
Expand Down
7 changes: 2 additions & 5 deletions lib/formatters/stylish-fixes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ try {
}
const getRuleURI = require('eslint-rule-documentation')

module.exports = function(results) {
module.exports = function (results) {
let output = '\n'
let errors = 0
let warnings = 0
Expand Down Expand Up @@ -82,8 +82,5 @@ function diff(a, b) {
fs.writeFileSync(aPath, a, {encoding: 'utf8'})
fs.writeFileSync(bPath, b, {encoding: 'utf8'})
const result = childProcess.spawnSync('diff', ['-U5', aPath, bPath], {encoding: 'utf8'})
return result.stdout
.split('\n')
.slice(2)
.join('\n')
return result.stdout.split('\n').slice(2).join('\n')
}
59 changes: 29 additions & 30 deletions lib/rules/get-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,36 @@ function isValidAttribute(name) {
return validSVGAttributeSet.has(name) || (validAttributeName.test(name) && !invalidSVGAttributeSet.has(name))
}

module.exports = function(context) {
return {
meta: {
type: 'problem',
docs: {
description: 'disallow wrong usage of attribute names',
url: require('../url')(module)
},
fixable: 'code',
schema: []
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'disallow wrong usage of attribute names',
url: require('../url')(module)
},
CallExpression(node) {
if (!node.callee.property) return

const calleeName = node.callee.property.name
if (!attributeCalls.test(calleeName)) return

const attributeNameNode = node.arguments[0]
if (!attributeNameNode) return

if (!isValidAttribute(attributeNameNode.value)) {
context.report({
meta: {
fixable: 'code'
},
node: attributeNameNode,
message: 'Attributes should be lowercase and hyphen separated, or part of the SVG whitelist.',
fix(fixer) {
return fixer.replaceText(attributeNameNode, `'${attributeNameNode.value.toLowerCase()}'`)
}
})
fixable: 'code',
schema: []
},
create(context) {
return {
CallExpression(node) {
if (!node.callee.property) return

const calleeName = node.callee.property.name
if (!attributeCalls.test(calleeName)) return

const attributeNameNode = node.arguments[0]
if (!attributeNameNode) return

if (!isValidAttribute(attributeNameNode.value)) {
context.report({
node: attributeNameNode,
message: 'Attributes should be lowercase and hyphen separated, or part of the SVG whitelist.',
fix(fixer) {
return fixer.replaceText(attributeNameNode, `'${attributeNameNode.value.toLowerCase()}'`)
}
})
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-blur.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(context) {
module.exports = function (context) {
return {
meta: {
type: 'problem',
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-useless-passive.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {

create(context) {
return {
['CallExpression[callee.property.name="addEventListener"]']: function(node) {
['CallExpression[callee.property.name="addEventListener"]']: function (node) {
const [name, listener, options] = node.arguments
if (name.type !== 'Literal') return
if (passiveEventListenerNames.has(name.value)) return
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {

create(context) {
return {
['CallExpression[callee.property.name="addEventListener"]']: function(node) {
['CallExpression[callee.property.name="addEventListener"]']: function (node) {
const [name] = node.arguments
if (name.type !== 'Literal') return
if (!(name.value in observerMap)) return
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/require-passive-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {

create(context) {
return {
['CallExpression[callee.property.name="addEventListener"]']: function(node) {
['CallExpression[callee.property.name="addEventListener"]']: function (node) {
const [name, listener, options] = node.arguments
if (!listener) return
if (name.type !== 'Literal') return
Expand Down
Loading

0 comments on commit bc687f5

Please sign in to comment.