Skip to content

Commit

Permalink
feat: forbid throw new error
Browse files Browse the repository at this point in the history
  • Loading branch information
vuki656 committed Aug 3, 2023
1 parent ef885a8 commit edd5694
Show file tree
Hide file tree
Showing 8 changed files with 2,650 additions and 4,190 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
1 change: 0 additions & 1 deletion cspell.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const config = {
"rimac",
"stylelint",
"packagerc",
"loglevel",
"pinst",
"commitlint",
"conventionalcommits",
Expand Down
39 changes: 19 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"lint:cspell": "cspell --no-progress --no-summary '**'",
"lint:eslint": "eslint './**/*.{js,ts,tsx}' --quiet --cache",
"lint:package-json": "npmPkgJsonLint --configFile ./.packagerc.js .",
"lint:prettier": "prettier --loglevel warn --check './**/*{yaml,yml,json,md}'",
"lint:prettier": "prettier --log-level warn --check './**/*{yaml,yml,json,md}'",
"prepublishOnly": "pinst --disable",
"postpublish": "pinst --enable",
"release": "semantic-release",
Expand All @@ -37,35 +37,34 @@
}
},
"devDependencies": {
"@commitlint/cli": "^17.4.4",
"@commitlint/config-conventional": "^17.4.4",
"@rimac-technology/style-guide": "^3.0.0",
"@semantic-release/changelog": "^6.0.2",
"@commitlint/cli": "^17.6.7",
"@commitlint/config-conventional": "^17.6.7",
"@rimac-technology/style-guide": "^8.1.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^9.0.2",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.7",
"@semantic-release/github": "^8.1.0",
"@semantic-release/npm": "^9.0.2",
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/dedent": "^0.7.0",
"@types/node": "^18.14.0",
"@typescript-eslint/parser": "^5.52.0",
"@typescript-eslint/utils": "^5.52.0",
"@types/node": "^18.17.1",
"@typescript-eslint/parser": "^5.62.0",
"@typescript-eslint/utils": "^5.62.0",
"commitizen": "^4.3.0",
"conventional-changelog-conventionalcommits": "^5.0.0",
"cspell": "^6.26.3",
"dedent": "^0.7.0",
"eslint": "8.34.0",
"eslint-plugin-eslint-plugin": "^5.0.8",
"cspell": "^6.31.2",
"dedent": "^1.5.1",
"eslint": "8.46.0",
"eslint-plugin-eslint-plugin": "^5.1.1",
"husky": "^8.0.3",
"jest": "^29.4.3",
"npm-package-json-lint": "^6.4.0",
"package-json-lint": "^0.0.2",
"jest": "^29.6.2",
"npm-package-json-lint": "^7.0.0",
"pinst": "^3.0.0",
"prettier": "^2.8.4",
"semantic-release": "^20.1.0",
"ts-jest": "^29.0.5",
"prettier": "^3.0.1",
"semantic-release": "^20.1.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.1.6"
},
"packageManager": "yarn@3.2.1",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/class-element-sorting/class-element-sorting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const value = createRule({
* have the same position, the element from the unsorted list is in the correct place.
*
* If when comparing elements, positions don't match, it means that the element from unsorted
* list was moved to another location in the sorted list and the class elements sequence is incorrect
* list was moved to another location in the sorted list and the class element sequence is incorrect
* and needs fixing.
*
*/
Expand Down
37 changes: 37 additions & 0 deletions src/rules/forbid-throw-new-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createRule } from '../utils'

const NAME = 'forbid-throw-new-error'

const value = createRule({
create(context) {
return {
Identifier(node) {
if (node.name === "Error") {
context.report({
loc: node.loc,
messageId: 'default',
})
}
},
}
},
defaultOptions: [],
meta: {
docs: {
description: 'Prevents throwing default errors',
recommended: false,
requiresTypeChecking: false,
},
messages: {
default: 'You must throw a domain specific error',
},
schema: [{ additionalProperties: false }],
type: 'problem',
},
name: NAME,
})

export default {
name: NAME,
value,
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ tsRuleTester.run<string, CypressConsistentActionNamesOptionsType[]>(rule.name, r
filename: TS_FILE_PATH,
options,
settings,
}],
}
],
valid: [{
code: dedent`
@TableActions
Expand Down
27 changes: 27 additions & 0 deletions src/tests/ts/rules/forbid-throw-new-error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import dedent from 'dedent'

import rule from '../../../rules/forbid-throw-new-error'
import {
TS_FILE_PATH,
tsRuleTester,
} from '../utils'

tsRuleTester.run(rule.name, rule.value, {
invalid: [
{
code: dedent`throw new Error("Something failed");`,
errors: [
{
column: 11,
line: 1,
messageId: 'default',
},
],
filename: TS_FILE_PATH,
},
],
valid: [{
code: dedent`throw new CustomError("Something failed");`,
filename: TS_FILE_PATH,
}],
})
Loading

0 comments on commit edd5694

Please sign in to comment.