Skip to content

Commit

Permalink
tsc improvements (#9)
Browse files Browse the repository at this point in the history
* Remove unused eslint plugins

* More strict typescript config
  • Loading branch information
darwintantuco authored Jan 23, 2021
1 parent db5caeb commit 2f69f0c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 160 deletions.
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:jsx-a11y/recommended',
'prettier/@typescript-eslint',
],
env: {
es6: true,
node: true,
browser: true,
jest: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
},
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All changes on this project will be documented in this file.

## [1.0.7] - January 23, 2021

- More strict typescript config
- Remove unused eslint plugins

## [1.0.6] - January 11, 2021

- Fix compilation issue
Expand Down
Binary file modified demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions lib/rules/in-code.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict'

import { Rule } from 'eslint'
import * as ESTree from 'estree'
import { searchForBadWords, isEmpty, buildErrorMessage } from '../util'

module.exports = {
create: (context) => {
create: (context: Rule.RuleContext): Rule.RuleListener => {
const settings = context.settings || {}
const customBadWords = settings.customBadWords || []

Expand All @@ -23,7 +25,7 @@ module.exports = {
}
},

JSXText(node) {
JSXText(node: ESTree.Literal) {
if (typeof node.value !== 'string') return

const result = searchForBadWords(customBadWords, node.value)
Expand Down
13 changes: 7 additions & 6 deletions lib/rules/in-comment.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict'

import { Rule } from 'eslint'
import * as ESTree from 'estree'
import { searchForBadWords, isEmpty, buildErrorMessage } from '../util'

module.exports = {
create: (context) => {
create: (context: Rule.RuleContext): Rule.RuleListener => {
const settings = context.settings || {}
const customBadWords = settings.customBadWords || []
const sourceCode = context.getSourceCode()

const validate = (comment) => {
const validate = (comment: ESTree.Comment) => {
if (!comment.loc || !comment.value) return
const result = searchForBadWords(customBadWords, comment.value)
if (!isEmpty(result)) {
context.report({
node: null,
loc: comment.loc,
message: buildErrorMessage(result[0].trim()),
})
Expand All @@ -23,9 +25,8 @@ module.exports = {

return {
Program() {
const comments = sourceCode.getAllComments()

comments.filter((token) => token.type !== 'Shebang').forEach(validate)
const comments: ESTree.Comment[] = sourceCode.getAllComments()
comments.forEach(validate)
},
}
},
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
{
"name": "eslint-plugin-detect-bad-words",
"version": "1.0.6",
"version": "1.0.7",
"description": "Detect bad/profanity words in code",
"main": "dist/index.js",
"keywords": [
"eslint",
"eslintplugin",
"eslint-plugin"
"eslint-plugin",
"profane",
"profanity",
"swear",
"curse"
],
"author": "Darwin Tantuco",
"prettier": "@darwintantuco/prettier-config",
Expand Down Expand Up @@ -40,7 +44,6 @@
"eslint": "^7.17.0",
"eslint-config-prettier": "^7.1.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"husky": "^4.2.5",
"mocha": "^7.2.0",
"npm-run-all": "^4.1.5",
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"allowJs": true,
"outDir": "./dist",
"strict": true,
"noImplicitAny": false,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
Expand All @@ -19,7 +19,7 @@
"noFallthroughCasesInSwitch": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"types": ["node"]
"typeRoots": ["./node_modules/@types", "./types"]
},
"include": ["lib/**/*.ts"]
}
1 change: 1 addition & 0 deletions types/badwords/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'badwords/object'
Loading

0 comments on commit 2f69f0c

Please sign in to comment.