diff --git a/CHANGELOG.md b/CHANGELOG.md index d29ee5a..b6906ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,11 @@ All changes on this project will be documented in this file. -## [1.0.5] - January 10, 2021 +## [1.0.6] - January 11, 2021 + +- Fix compilation issue + +## [1.0.5] - January 11, 2021 - Initial release - Rename package from `eslint-plugin-detect-unwanted-words` to `eslint-plugin-detect-bad-words` diff --git a/lib/rules/in-code.ts b/lib/rules/in-code.ts index 7759cda..6cd58e5 100644 --- a/lib/rules/in-code.ts +++ b/lib/rules/in-code.ts @@ -2,56 +2,56 @@ import { searchForBadWords, isEmpty, buildErrorMessage } from '../util' -const create = (context) => { - const settings = context.settings || {} - const customBadWords = settings.customBadWords || [] - - return { - Literal(node) { - if (typeof node.value !== 'string') return - - const result = searchForBadWords(customBadWords, node.value) - - if (!isEmpty(result)) { - context.report({ - node, - message: buildErrorMessage(result[0].trim()), - }) - } else { - return - } - }, - - JSXText(node) { - if (typeof node.value !== 'string') return - - const result = searchForBadWords(customBadWords, node.value) - - if (!isEmpty(result)) { - context.report({ - node, - message: buildErrorMessage(result[0].trim()), - }) - } else { - return - } - }, - - Identifier(node) { - if (typeof node.name !== 'string') return - - const result = searchForBadWords(customBadWords, node.name) - - if (!isEmpty(result)) { - context.report({ - node, - message: buildErrorMessage(result[0].trim()), - }) - } else { - return - } - }, - } +module.exports = { + create: (context) => { + const settings = context.settings || {} + const customBadWords = settings.customBadWords || [] + + return { + Literal(node) { + if (typeof node.value !== 'string') return + + const result = searchForBadWords(customBadWords, node.value) + + if (!isEmpty(result)) { + context.report({ + node, + message: buildErrorMessage(result[0].trim()), + }) + } else { + return + } + }, + + JSXText(node) { + if (typeof node.value !== 'string') return + + const result = searchForBadWords(customBadWords, node.value) + + if (!isEmpty(result)) { + context.report({ + node, + message: buildErrorMessage(result[0].trim()), + }) + } else { + return + } + }, + + Identifier(node) { + if (typeof node.name !== 'string') return + + const result = searchForBadWords(customBadWords, node.name) + + if (!isEmpty(result)) { + context.report({ + node, + message: buildErrorMessage(result[0].trim()), + }) + } else { + return + } + }, + } + }, } - -export default { create } diff --git a/lib/rules/in-comment.ts b/lib/rules/in-comment.ts index fe29df4..897ea6a 100644 --- a/lib/rules/in-comment.ts +++ b/lib/rules/in-comment.ts @@ -2,31 +2,31 @@ import { searchForBadWords, isEmpty, buildErrorMessage } from '../util' -const create = (context) => { - const settings = context.settings || {} - const customBadWords = settings.customBadWords || [] - const sourceCode = context.getSourceCode() +module.exports = { + create: (context) => { + const settings = context.settings || {} + const customBadWords = settings.customBadWords || [] + const sourceCode = context.getSourceCode() - const validate = (comment) => { - const result = searchForBadWords(customBadWords, comment.value) - if (!isEmpty(result)) { - context.report({ - node: null, - loc: comment.loc, - message: buildErrorMessage(result[0].trim()), - }) - } else { - return + const validate = (comment) => { + const result = searchForBadWords(customBadWords, comment.value) + if (!isEmpty(result)) { + context.report({ + node: null, + loc: comment.loc, + message: buildErrorMessage(result[0].trim()), + }) + } else { + return + } } - } - return { - Program() { - const comments = sourceCode.getAllComments() + return { + Program() { + const comments = sourceCode.getAllComments() - comments.filter((token) => token.type !== 'Shebang').forEach(validate) - }, - } + comments.filter((token) => token.type !== 'Shebang').forEach(validate) + }, + } + }, } - -export default { create } diff --git a/package.json b/package.json index 7b6c791..47945dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-detect-bad-words", - "version": "1.0.5", + "version": "1.0.6", "description": "Detect bad/profanity words in code", "main": "dist/index.js", "keywords": [ diff --git a/tests/rules/in-code.ts b/tests/rules/in-code.ts index c6ca5c6..c6e9a60 100644 --- a/tests/rules/in-code.ts +++ b/tests/rules/in-code.ts @@ -2,8 +2,10 @@ export {} +// eslint-disable-next-line +const rule = require('../../lib/rules/in-code') + import { RuleTester } from 'eslint' -import rule from '../../lib/rules/in-code' import { buildErrorMessage } from '../../lib/util' const parserOptions = { diff --git a/tests/rules/in-comment.ts b/tests/rules/in-comment.ts index 79a7d5d..1a9bb46 100644 --- a/tests/rules/in-comment.ts +++ b/tests/rules/in-comment.ts @@ -2,8 +2,10 @@ export {} +// eslint-disable-next-line +const rule = require('../../lib/rules/in-comment') + import { RuleTester } from 'eslint' -import rule from '../../lib/rules/in-comment' import { buildErrorMessage } from '../../lib/util' const parserOptions = {