@nkzw/eslint-plugin 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Christoph Nakazawa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # `@nkzw/eslint-plugin`
2
+
3
+ ESLint rules for Nakazawa Tech. Use this plugin together with [`@nkzw/eslint-config`](https://github.com/cpojer/eslint-config).
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ const noInstanceof = require('./rules/no-instanceof');
2
+
3
+ module.exports = {
4
+ configs: {
5
+ strict: {
6
+ rules: {
7
+ '@nkzw/no-instanceof': 2,
8
+ },
9
+ },
10
+ },
11
+ rules: {
12
+ 'no-instanceof': noInstanceof,
13
+ },
14
+ };
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@nkzw/eslint-plugin",
3
+ "version": "1.8.0",
4
+ "description": "ESLint plugins for Nakazawa Tech.",
5
+ "author": "Christoph Nakazawa <christoph.pojer@gmail.com>",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git://github.com/cpojer/eslint-plugin.git"
9
+ },
10
+ "main": "index.js",
11
+ "keywords": [],
12
+ "license": "MIT",
13
+ "devDependencies": {
14
+ "eslint": "^8.50.0"
15
+ },
16
+ "peerDependencies": {
17
+ "eslint": ">= 8"
18
+ },
19
+ "scripts": {
20
+ "test": "node test test.js"
21
+ }
22
+ }
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ create(context) {
5
+ return {
6
+ BinaryExpression(node) {
7
+ if (
8
+ node.type === 'BinaryExpression' &&
9
+ node.operator === 'instanceof'
10
+ ) {
11
+ if (
12
+ node.right.type === 'Identifier' &&
13
+ (node.right.name.endsWith('Error') ||
14
+ node.right.name.endsWith('Exception'))
15
+ ) {
16
+ return;
17
+ }
18
+ context.report({
19
+ message: 'The "instanceof" operator is not allowed.',
20
+ node,
21
+ });
22
+ }
23
+ },
24
+ };
25
+ },
26
+ };
package/test.js ADDED
@@ -0,0 +1,24 @@
1
+ const RuleTester = require('eslint').RuleTester;
2
+ const rule = require('./rules/no-instanceof');
3
+
4
+ const ruleTester = new RuleTester();
5
+
6
+ ruleTester.run('@nkzw/no-instanceof', rule, {
7
+ valid: [
8
+ 'if (value instanceof Error) {}',
9
+ 'if (value instanceof CustomError) {}',
10
+ 'if (value instanceof Exception) {}',
11
+ 'if (value instanceof CustomException) {}',
12
+ ],
13
+ invalid: [
14
+ {
15
+ code: 'if (value instanceof CustomClass) {}',
16
+ errors: [
17
+ {
18
+ message: 'The "instanceof" operator is not allowed.',
19
+ type: 'BinaryExpression',
20
+ },
21
+ ],
22
+ },
23
+ ],
24
+ });