Skip to content

Commit 65c774a

Browse files
authored
Project Init (#1)
### ESLint Plugin for AssemblyScript: * Created two sets of rules: `asPlugin` for AssemblyScript language rules and `perfPlugin` for performance optimization rules. Current implemented rules are `dont-omit-else`, `no-spread`, `no-unsupported-keyword`, and `array-init-style`. (`plugins/asPlugin.ts`, `plugins/perfPlugin.ts`, `plugins/rules/*`) [[1]](diffhunk://#diff-c0b46ba160117ac54a3f360ff53dc85bb6a5f2ba342e99d0735670a27980a12dR1-R18) [[2]](diffhunk://#diff-60d5a6b7617e8cc6b93b305f375a86b8ad208eb1890e1a411dfd84588d4b07ccR1-R13) [[3]](diffhunk://#diff-547b5cd9d1f05669a90c496b3c1705d80bc46aaa6387dbe35020c95f2a900145R1-R65) [[4]](diffhunk://#diff-56c2dcf56fa3969834eeba79d6c087553996f45b5f6e871759db1b1a3f33e4d2R1-R86) [[5]](diffhunk://#diff-afa12ab290d6de40b8cd41f63ddf94eaf500780e632ee97b0c9a1678c7e006ecR1-R40) [[6]](diffhunk://#diff-ef3ad7df6c2ccbca80280f8b5c3063082e64a807040d4f07de8192b7f0701a7eR1-R48) * Added documentation for each rule, explaining their purpose, usage, and examples. (`docs/rules/array-init-style.md`, `docs/rules/dont-omit-else.md`, `docs/rules/no-spread.md`, `docs/rules/no-unsupported-keyword.md`) [[1]](diffhunk://#diff-d2ee6f771e0116b9e11609d2b1683c1bb2a8a77efc141cef4e645cd5be1c55e7R1-R25) [[2]](diffhunk://#diff-cb2b4875d22ce10c641c14d950391902a59a0d78104c92bc80343ebd7f817521R1-R47) [[3]](diffhunk://#diff-40b55447478cb0d11c5464aa80c68744c0c0c8c0ce486e1e4204f29f46321d21R1-R47) [[4]](diffhunk://#diff-a599e2ebc70e93a1575ccb96d5c4b3557591a6f6cb12cddb9d98dd205f415a05R1-R59) #### Standard Rules (`asPlugin.ts`) Enforces AssemblyScript language compatibility: - `dont-omit-else`: Requires explicit `else` blocks for conditionals that don't have early return statements. - `no-spread`: Prevents use of spread syntax (`...`) which is not supported in AssemblyScript - `no-unsupported-keyword`: Disallows TypeScript keywords not supported in AssemblyScript (`any`, `never`, `undefined`) #### Performance Rules (`perfPlugin.ts`) Optimizes code for better WebAssembly performance: - `array-init-style`: Recommends using `new Array<T>()` instead of `[]` for initializing empty arrays ### Development Environment Setup: * Configured CI workflows to automate testing, linting, spell-checking, and code formatting. (`.github/workflows/ci.yml`) * Added Prettier configuration and ignore files for consistent code formatting. (`.prettierrc.yaml`, `.prettierignore`) [[1]](diffhunk://#diff-3658ca8ad2a159675c1e1ba5c0b743a851c9d356ca5776dd047f639bfd73de25R1-R18) [[2]](diffhunk://#diff-b640b344ee7f3f03d2a443795a5d0708ef50e2e6e34214109ab2aad13ad6ba98R1-R8) * Introduced a spell-check configuration (`cspell.json`) and a project-specific dictionary (`cspell/project-words.txt`) to ensure proper spelling in code and documentation. [[1]](diffhunk://#diff-77519f787fe7e051a14c588f101d61e4d8f0d3b01bf8e16cb65d3838243d4e68R1-R27) [[2]](diffhunk://#diff-422a965a191f047c5bf668bcd269fb4e6968972bf2996a3bcc406e37bef609a5R1-R48)
1 parent 4835eb2 commit 65c774a

32 files changed

+9732
-1
lines changed

.c8rc.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"all": true,
3+
"include": ["dist/plugins/rules/**/*.js"],
4+
"reporter": ["text", "html", "lcov"],
5+
"report-dir": "./coverage",
6+
"check-coverage": true,
7+
"branches": 95,
8+
"lines": 95,
9+
"functions": 95,
10+
"statements": 95
11+
}

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: "22.3.x"
19+
20+
- name: Install dependencies
21+
run: npm ci
22+
23+
- name: Run build
24+
run: npm run build
25+
26+
- name: Run spell check
27+
run: npm run spell-check
28+
29+
- name: Run prettier
30+
run: npm run prettier-check
31+
32+
- name: Run lint
33+
run: npm run lint
34+
35+
- name: Run test & coverage
36+
run: npm run test:coverage

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules
2+
dist/
3+
sample_cases/
4+
wasm-toolchain
5+
coverage
6+
.vscode
7+
reference

.prettierignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/node_modules/**
2+
dist/**
3+
reference/**
4+
sample_cases/**
5+
sample_config/**
6+
build/**
7+
wasm-toolchain/**
8+
coverage/**

.prettierrc.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
arrowParens: always
2+
bracketSpacing: true
3+
endOfLine: lf
4+
htmlWhitespaceSensitivity: css
5+
insertPragma: false
6+
singleAttributePerLine: false
7+
bracketSameLine: false
8+
jsxSingleQuote: false
9+
printWidth: 80
10+
proseWrap: preserve
11+
quoteProps: as-needed
12+
requirePragma: false
13+
semi: true
14+
singleQuote: false
15+
tabWidth: 2
16+
trailingComma: es5
17+
useTabs: false
18+
embeddedLanguageFormatting: auto

Readme.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
This repo contains eslint rules for assemblyscript
1+
# ESLint Plugin for AssemblyScript
2+
3+
An ESLint plugin that helps developers write better AssemblyScript code by enforcing language-specific rules and best practices.
4+
5+
## Overview
6+
7+
This plugin provides two sets of rules:
8+
9+
- **Language Standards**: Rules that enforce AssemblyScript language restrictions and prevent errors
10+
- **Performance Optimization**: Rules that help improve code performance in WebAssembly
11+
12+
## Plugins Included
13+
14+
### Standard Rules (`asPlugin.ts`)
15+
16+
Enforces AssemblyScript language compatibility:
17+
18+
- `dont-omit-else`: Requires explicit `else` blocks for conditionals that don't have early return statements
19+
- `no-spread`: Prevents use of spread syntax (`...`) which is not supported in AssemblyScript
20+
- `no-unsupported-keyword`: Disallows TypeScript keywords not supported in AssemblyScript (`any`, `never`, `undefined`)
21+
22+
### Performance Rules (`perfPlugin.ts`)
23+
24+
Optimizes code for better WebAssembly performance:
25+
26+
- `array-init-style`: Recommends using `new Array<T>()` instead of `[]` for initializing empty arrays
27+
28+
## Configuration
29+
30+
See `sample_config/sample_eslint.config.mjs` for a detailed example of how to configure and use this plugin.
31+
32+
## Documentation
33+
34+
For detailed rule documentation, see the [docs/rules](./docs/rules) directory.

cspell.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "0.2",
3+
"language": "en",
4+
"words": [],
5+
"dictionaries": ["typescript", "node", "npm", "project-words"],
6+
"dictionaryDefinitions": [
7+
{
8+
"name": "project-words",
9+
"path": "cspell/project-words.txt",
10+
"description": "Project specific words"
11+
}
12+
],
13+
"ignorePaths": [
14+
"/node_modules/**",
15+
"dist/**",
16+
"reference/**",
17+
"sample_cases/**",
18+
"sample_config/**",
19+
"build/**",
20+
"tests/**",
21+
"wasm-toolchain/**",
22+
"coverage/**",
23+
".github/**",
24+
"**/*.json",
25+
"**/*.md"
26+
]
27+
}

cspell/project-words.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
assemblyscript
2+
wasm
3+
webassembly
4+
eslint
5+
linter
6+
linting
7+
ruleset
8+
rulename
9+
messageId
10+
autofix
11+
autofixer
12+
codefix
13+
ast
14+
sourcecode
15+
parserservices
16+
typechecker
17+
tsconfig
18+
tseslint
19+
tses
20+
21+
// AssemblyScript types and keywords
22+
i8
23+
i16
24+
i32
25+
i64
26+
27+
// Performance optimization terms
28+
perf
29+
benchmarking
30+
memcpy
31+
32+
// Common variable/function name abbreviations
33+
ctx
34+
params
35+
args
36+
37+
// Tools and frameworks
38+
mocha
39+
tsx
40+
tester
41+
42+
// Project directories and files
43+
dist
44+
plugins
45+
cspell
46+
47+
// rule keywords
48+
dont

docs/rules/array-init-style.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# array-init-style
2+
3+
> Enforce using Array constructor for empty array initialization
4+
5+
## Rule Details
6+
7+
In AssemblyScript, using the literal `[]` to create empty arrays creates a temporary object in the data section, which may lead to performance issues. This rule enforces using the `new Array<T>()` constructor to initialize empty arrays.
8+
9+
## Rule Options
10+
11+
This rule has no configuration options.
12+
13+
## Examples
14+
15+
### Incorrect
16+
17+
```ts
18+
let arr: i32[] = []; // not recommended
19+
```
20+
21+
### Correct
22+
23+
```ts
24+
let arr: i32[] = new Array<i32>(); // recommended
25+
```

docs/rules/dont-omit-else.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# dont-omit-else
2+
3+
> Enforce using else block when if branch doesn't contain control flow statement
4+
5+
## Rule Details
6+
7+
In AssemblyScript, it's recommended to explicitly handle all possible execution paths for better code clarity and safety. This rule enforces using an `else` block when the `if` branch doesn't contain a statement that alters the control flow, such as `return`, `throw`, `break`, or `continue`.
8+
9+
## Rule Options
10+
11+
This rule has no configuration options.
12+
13+
## Examples
14+
15+
### Incorrect
16+
17+
```ts
18+
if (condition) {
19+
doSomething();
20+
} // missing else
21+
```
22+
23+
### Correct
24+
25+
```ts
26+
// With else block
27+
if (condition) {
28+
doSomething();
29+
} else {
30+
doSomethingElse();
31+
}
32+
33+
// Or with early exit in if branch
34+
if (condition) {
35+
doSomething();
36+
return; // Control flow statement makes else unnecessary
37+
}
38+
// Execution continues here only if condition is false
39+
```
40+
41+
## When Not To Use
42+
43+
You can disable this rule if you prefer a coding style that doesn't require explicit else blocks for all conditional statements.
44+
45+
## Related Rules
46+
47+
None

0 commit comments

Comments
 (0)