@cloudalgo/eslint-parser-apex 0.1.8 → 0.1.10

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.
Files changed (2) hide show
  1. package/README.md +93 -0
  2. package/package.json +3 -2
package/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # @cloudalgo/eslint-parser-apex
2
+
3
+ ESLint custom parser for Salesforce Apex. Bridges `@apexdevtools/apex-parser` (the same ANTLR grammar PMD 7 uses) into an ESTree-compatible AST that ESLint can traverse.
4
+
5
+ Used internally by [`@cloudalgo/eslint-plugin-apex`](https://www.npmjs.com/package/@cloudalgo/eslint-plugin-apex). You only need to install this directly if you want to write your own ESLint rules for Apex without using the plugin.
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install --save-dev @cloudalgo/eslint-parser-apex
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Usage with ESLint v9 (flat config)
18
+
19
+ ```js
20
+ // eslint.config.js
21
+ import apexParser from "@cloudalgo/eslint-parser-apex";
22
+
23
+ export default [
24
+ {
25
+ files: ["**/*.cls", "**/*.trigger"],
26
+ languageOptions: {
27
+ parser: apexParser,
28
+ },
29
+ },
30
+ ];
31
+ ```
32
+
33
+ ## Usage with ESLint v8 (legacy config)
34
+
35
+ ```json
36
+ // .eslintrc.json
37
+ {
38
+ "parser": "@cloudalgo/eslint-parser-apex",
39
+ "rules": {}
40
+ }
41
+ ```
42
+
43
+ ---
44
+
45
+ ## What the parser produces
46
+
47
+ Each Apex parse-tree node is wrapped as an ESTree node with:
48
+
49
+ ```ts
50
+ {
51
+ type: string; // constructor name from the ANTLR grammar (e.g. "QueryContext")
52
+ body: ApexNode[]; // child context nodes (terminal tokens are excluded)
53
+ loc: { start, end }; // line/column from ANTLR token positions
54
+ range: [number, number]; // byte offsets
55
+ _antlr: any; // the raw ANTLR context, available in rule visitors
56
+ }
57
+ ```
58
+
59
+ The root is wrapped in a synthetic `type: "Program"` node so ESLint's internal validation passes.
60
+
61
+ ---
62
+
63
+ ## Writing rules with this parser
64
+
65
+ The visitor key in your ESLint rule is the ANTLR context constructor name:
66
+
67
+ ```js
68
+ // my-rule.js
69
+ export default {
70
+ create(context) {
71
+ return {
72
+ // fires for every SOQL query
73
+ QueryContext(node) {
74
+ context.report({ node, message: "Found a SOQL query." });
75
+ },
76
+ };
77
+ },
78
+ };
79
+ ```
80
+
81
+ Inspect `node._antlr.constructor.name` while walking a sample file to discover available context types. The grammar is `@apexdevtools/apex-parser`.
82
+
83
+ ---
84
+
85
+ ## Simpler alternative
86
+
87
+ If you want ready-made rules rather than writing your own, use [`@cloudalgo/eslint-plugin-apex`](https://www.npmjs.com/package/@cloudalgo/eslint-plugin-apex) which bundles this parser with 41 built-in rules.
88
+
89
+ ---
90
+
91
+ ## Repository
92
+
93
+ [github.com/cloudalgo/apex-lint](https://github.com/cloudalgo/apex-lint) · License: BSD-3-Clause
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudalgo/eslint-parser-apex",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "ESLint custom parser for Salesforce Apex — bridges @apexdevtools/apex-parser to ESTree",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,8 @@
9
9
  ".": "./dist/index.js"
10
10
  },
11
11
  "files": [
12
- "dist"
12
+ "dist",
13
+ "README.md"
13
14
  ],
14
15
  "dependencies": {
15
16
  "@apexdevtools/apex-parser": "^5.0.0"