Skip to content

Commit

Permalink
Fix compilation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
darwintantuco committed Jan 11, 2021
1 parent a8e92c6 commit db5caeb
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 79 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
104 changes: 52 additions & 52 deletions lib/rules/in-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
46 changes: 23 additions & 23 deletions lib/rules/in-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
4 changes: 3 additions & 1 deletion tests/rules/in-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 3 additions & 1 deletion tests/rules/in-comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit db5caeb

Please sign in to comment.