@puruslang/linter 0.3.1 → 0.4.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +26 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@puruslang/linter",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "Linter for the Purus language",
5
5
  "license": "Apache-2.0",
6
6
  "main": "src/index.js",
package/src/index.js CHANGED
@@ -10,7 +10,7 @@ const KEYWORDS = new Set([
10
10
  "import", "from", "export", "default", "require", "use", "namespace", "pub", "all",
11
11
  "add", "sub", "mul", "div", "mod", "neg", "pow",
12
12
  "eq", "neq", "lt", "gt", "le", "ge",
13
- "and", "or", "not", "pipe",
13
+ "and", "or", "not", "pipe", "coal",
14
14
  "is", "as", "of", "typeof", "instanceof", "type",
15
15
  "new", "delete", "this", "await",
16
16
  "true", "false", "null", "nil", "undefined",
@@ -80,16 +80,37 @@ function tokenize(source) {
80
80
  }
81
81
 
82
82
  // Punctuation
83
- if ("[],;.".includes(source[i])) {
83
+ if ("[],;".includes(source[i])) {
84
+ tokens.push({ type: "punct", value: source[i], line: startLine, col: startCol });
85
+ i++; col++;
86
+ continue;
87
+ }
88
+
89
+ // Optional chaining \.
90
+ if (source[i] === "\\" && source[i + 1] === ".") {
91
+ tokens.push({ type: "punct", value: "\\.", line: startLine, col: startCol });
92
+ i += 2; col += 2;
93
+ continue;
94
+ }
95
+
96
+ // Backslash (computed access prefix)
97
+ if (source[i] === "\\") {
98
+ tokens.push({ type: "punct", value: "\\", line: startLine, col: startCol });
99
+ i++; col++;
100
+ continue;
101
+ }
102
+
103
+ // Dot
104
+ if (source[i] === ".") {
84
105
  tokens.push({ type: "punct", value: source[i], line: startLine, col: startCol });
85
106
  i++; col++;
86
107
  continue;
87
108
  }
88
109
 
89
110
  // Word
90
- if (/[a-zA-Z]/.test(source[i])) {
111
+ if (/[a-zA-Z_]/.test(source[i])) {
91
112
  let start = i;
92
- while (i < len && /[a-zA-Z0-9-]/.test(source[i])) { i++; col++; }
113
+ while (i < len && /[a-zA-Z0-9_-]/.test(source[i])) { i++; col++; }
93
114
  const word = source.slice(start, i);
94
115
  tokens.push({ type: KEYWORDS.has(word) ? "keyword" : "ident", value: word, line: startLine, col: startCol });
95
116
  continue;
@@ -167,11 +188,8 @@ function lint(source, ruleOverrides = {}) {
167
188
  if (style === "kebab-case") {
168
189
  // Identifiers should be kebab-case (lowercase with hyphens)
169
190
  // Allow PascalCase for class names (starts with uppercase)
191
+ // Allow underscores (they are equivalent to hyphens)
170
192
  if (/[A-Z]/.test(tok.value[0])) continue; // Allow PascalCase
171
- if (/_/.test(tok.value)) {
172
- report("consistent-naming", tok.line, tok.col,
173
- `Use kebab-case instead of snake_case: '${tok.value}'`);
174
- }
175
193
  }
176
194
  }
177
195
  }