Skip to content

Commit 49e0691

Browse files
committed
comply with eslint rules
1 parent 8b6642e commit 49e0691

17 files changed

+63
-55
lines changed

.c8rc.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
{
22
"all": true,
3-
"include": [
4-
"dist/plugins/rules/**/*.js"
5-
],
3+
"include": ["dist/plugins/rules/**/*.js"],
64
"reporter": ["text", "html", "lcov"],
75
"report-dir": "./coverage",
86
"check-coverage": true,
97
"branches": 95,
108
"lines": 95,
119
"functions": 95,
1210
"statements": 95
13-
}
11+
}

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import perfPlugin from "./dist/plugins/perf-plugin.js";
2-
import asPlugin from "./dist/plugins/as-plugin.js";
1+
import perfPlugin from "./dist/plugins/perfPlugin.js";
2+
import asPlugin from "./dist/plugins/asPlugin.js";
33

44
export default {
55
rules: {

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{
22
"name": "assemblyscript-eslint-plugin",
33
"version": "1.0.0",
4+
"engines": {
5+
"node": ">=16.6.0"
6+
},
47
"description": "Provides linting plugin for assemblyscript",
58
"keywords": [
69
"assemblyscript",
@@ -44,6 +47,7 @@
4447
"@types/mocha": "^10.0.10",
4548
"@types/node": "^22.14.1",
4649
"@typescript-eslint/rule-tester": "^8.30.1",
50+
"@typescript-eslint/utils": "^8.32.1",
4751
"c8": "^10.1.3",
4852
"cspell": "^9.0.1",
4953
"mocha": "^11.2.2",

plugins/as-plugin.ts renamed to plugins/asPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* It detects patterns that are either not supported in AssemblyScript
66
* or violate best practices specific to the language.
77
*/
8-
import dontOmitElse from "./rules/dont-omit-else.js";
9-
import noSpread from "./rules/no-spread.js";
10-
import noUnsupportedKeyword from "./rules/no-unsupported-keyword.js";
8+
import dontOmitElse from "./rules/dontOmitElse.js";
9+
import noSpread from "./rules/noSpread.js";
10+
import noUnsupportedKeyword from "./rules/noUnsupportedKeyword.js";
1111

1212
export default {
1313
rules: {

plugins/perf-plugin.ts renamed to plugins/perfPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This plugin provides rules for detecting and fixing potential performance issues
55
* in AssemblyScript code.
66
*/
7-
import arrayInitStyle from "./rules/array-init-style.js";
7+
import arrayInitStyle from "./rules/arrayInitStyle.js";
88

99
export default {
1010
rules: {

plugins/rules/array-init-style.ts renamed to plugins/rules/arrayInitStyle.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ESLintUtils } from "@typescript-eslint/utils";
2-
import createRule from "../utils/create-rule.js";
1+
import { ESLintUtils, AST_NODE_TYPES } from "@typescript-eslint/utils";
2+
import createRule from "../utils/createRule.js";
33

44
/**
55
* Rule: Array Initializer
@@ -35,9 +35,9 @@ const arrayInitStyle: ESLintUtils.RuleModule<
3535
VariableDeclarator(node) {
3636
const typeAnnotation = node.id.typeAnnotation?.typeAnnotation;
3737
if (
38-
typeAnnotation?.type === "TSArrayType" &&
39-
typeAnnotation.elementType?.type === "TSTypeReference" &&
40-
node.init?.type === "ArrayExpression" &&
38+
typeAnnotation?.type === AST_NODE_TYPES.TSArrayType &&
39+
typeAnnotation.elementType?.type === AST_NODE_TYPES.TSTypeReference &&
40+
node.init?.type === AST_NODE_TYPES.ArrayExpression &&
4141
node.init.elements.length === 0
4242
) {
4343
// Ensure node.init is not null before passing to fixer

plugins/rules/dont-omit-else.ts renamed to plugins/rules/dontOmitElse.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { TSESTree } from "@typescript-eslint/utils";
1+
import { TSESTree, AST_NODE_TYPES } from "@typescript-eslint/utils";
22
import { RuleListener, RuleModule } from "@typescript-eslint/utils/ts-eslint";
3-
import createRule from "../utils/create-rule.js";
3+
import createRule from "../utils/createRule.js";
44

55
/**
66
* Rule: Dont Omit Else
@@ -10,6 +10,30 @@ import createRule from "../utils/create-rule.js";
1010
* GOOD
1111
* if (x) { } else { }
1212
*/
13+
14+
// Helper function to check if a node will lead to early exit
15+
function isEarlyExitStatement(node: TSESTree.Node): boolean {
16+
// Return true if the node will lead to early exit
17+
return (
18+
node.type === AST_NODE_TYPES.ReturnStatement ||
19+
node.type === AST_NODE_TYPES.ThrowStatement ||
20+
node.type === AST_NODE_TYPES.BreakStatement ||
21+
node.type === AST_NODE_TYPES.ContinueStatement
22+
);
23+
}
24+
// Check if statement or block doesn't contain early exit statement
25+
function hasTerminatingStatement(node: TSESTree.Node) {
26+
// Handle different statement types
27+
if (node.type === AST_NODE_TYPES.BlockStatement) {
28+
// For block statements, check the last statement in the block
29+
const lastStatement = node.body.length > 0 ? node.body.at(-1) : null;
30+
return lastStatement ? isEarlyExitStatement(lastStatement) : false;
31+
} else {
32+
// For single statements (no curly braces), check the statement directly
33+
return isEarlyExitStatement(node);
34+
}
35+
}
36+
1337
const dontOmitElse: RuleModule<"omittedElse", [], unknown, RuleListener> =
1438
createRule({
1539
name: "dont-omit-else",
@@ -31,33 +55,12 @@ const dontOmitElse: RuleModule<"omittedElse", [], unknown, RuleListener> =
3155
function isElseIfChain(node: TSESTree.IfStatement) {
3256
const ancestors = context.sourceCode.getAncestors(node);
3357
const parent = ancestors.at(-1);
34-
return parent?.type === "IfStatement" && parent.alternate === node;
35-
}
36-
37-
// Helper function to check if a node will lead to early exit
38-
function isEarlyExitStatement(node: TSESTree.Node): boolean {
39-
// Return true if the node will lead to early exit
4058
return (
41-
node.type === "ReturnStatement" ||
42-
node.type === "ThrowStatement" ||
43-
node.type === "BreakStatement" ||
44-
node.type === "ContinueStatement"
59+
parent?.type === AST_NODE_TYPES.IfStatement &&
60+
parent.alternate === node
4561
);
4662
}
4763

48-
// Check if statement or block doesn't contain early exit statement
49-
function hasTerminatingStatement(node: TSESTree.Node) {
50-
// Handle different statement types
51-
if (node.type === "BlockStatement") {
52-
// For block statements, check the last statement in the block
53-
const lastStatement = node.body.length > 0 ? node.body.at(-1) : null;
54-
return lastStatement ? isEarlyExitStatement(lastStatement) : false;
55-
} else {
56-
// For single statements (no curly braces), check the statement directly
57-
return isEarlyExitStatement(node);
58-
}
59-
}
60-
6164
return {
6265
IfStatement(node) {
6366
// Skip if this is already an else-if

plugins/rules/no-spread.ts renamed to plugins/rules/noSpread.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ESLintUtils } from "@typescript-eslint/utils";
2-
import createRule from "../utils/create-rule.js";
2+
import createRule from "../utils/createRule.js";
33

44
/**
55
* Rule: No Spread

plugins/rules/no-unsupported-keyword.ts renamed to plugins/rules/noUnsupportedKeyword.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ESLintUtils } from "@typescript-eslint/utils";
2-
import createRule from "../utils/create-rule.js";
2+
import createRule from "../utils/createRule.js";
33

44
/**
55
* Rule: No Unsupported Keywords
File renamed without changes.

0 commit comments

Comments
 (0)