@ripple-ts/eslint-parser 0.3.17 → 0.3.19

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![npm downloads](https://img.shields.io/npm/dm/%40ripple-ts%2Feslint-parser?logo=npm&label=downloads)](https://www.npmjs.com/package/@ripple-ts/eslint-parser)
5
5
 
6
6
  ESLint parser for Ripple component files. This parser enables ESLint to understand
7
- and lint `.tsrx` files by default, while also supporting `.ripple` files through
7
+ and lint `.tsrx` files by default, while also supporting `.tsrx` files through
8
8
  Ripple's built-in compiler.
9
9
 
10
10
  ## Installation
@@ -50,7 +50,7 @@ export default [
50
50
  {
51
51
  "overrides": [
52
52
  {
53
- "files": ["*.tsrx", "*.ripple"],
53
+ "files": ["*.tsrx", "*.tsrx"],
54
54
  "parser": "@ripple-ts/eslint-parser",
55
55
  "plugins": ["ripple"],
56
56
  "extends": ["plugin:ripple/recommended"]
@@ -68,7 +68,7 @@ already outputs ESTree-compliant ASTs, making integration straightforward.
68
68
  The parser:
69
69
 
70
70
  1. Loads the Ripple compiler
71
- 2. Parses the component source code (`.tsrx` or `.ripple`)
71
+ 2. Parses the component source code (`.tsrx` or `.tsrx`)
72
72
  3. Returns the ESTree AST to ESLint
73
73
  4. Allows ESLint rules to analyze Ripple-specific patterns
74
74
 
package/dist/index.d.ts CHANGED
@@ -504,9 +504,9 @@ interface ParseResult {
504
504
  visitorKeys?: Record<string, string[]>;
505
505
  }
506
506
  /**
507
- * ESLint parser for Ripple (.ripple) files
507
+ * ESLint parser for Ripple (.tsrx) files
508
508
  *
509
- * This parser uses Ripple's built-in compiler to parse .ripple files
509
+ * This parser uses Ripple's built-in compiler to parse .tsrx files
510
510
  * and returns an ESTree-compatible AST for ESLint to analyze.
511
511
  */
512
512
  declare function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult;
package/dist/index.js CHANGED
@@ -79,9 +79,9 @@ function ensureNodeProperties(node, code) {
79
79
  }
80
80
  }
81
81
  /**
82
- * ESLint parser for Ripple (.ripple) files
82
+ * ESLint parser for Ripple (.tsrx) files
83
83
  *
84
- * This parser uses Ripple's built-in compiler to parse .ripple files
84
+ * This parser uses Ripple's built-in compiler to parse .tsrx files
85
85
  * and returns an ESTree-compatible AST for ESLint to analyze.
86
86
  */
87
87
  function parseForESLint(code, options) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Program } from 'estree';\nimport type { Linter } from 'eslint';\nimport { createRequire } from 'module';\n\ninterface ParseResult {\n\tast: Program;\n\tservices?: Record<string, any>;\n\tscopeManager?: any;\n\tvisitorKeys?: Record<string, string[]>;\n}\n\n/**\n * The Ripple compiler's AST contains some redundant references (e.g. `Element.attributes`\n * and `Element.openingElement.attributes`) that are useful for formatters/source-maps.\n * ESLint's traverser will visit both paths and can trigger duplicate rule reports.\n *\n * For ESLint, we prune JSX wrapper nodes to keep a single traversal path.\n */\nfunction normalizeRippleAstForEslint(ast: any): void {\n\tconst seen = new Set<any>();\n\tconst visit = (node: any) => {\n\t\tif (!node || typeof node !== 'object') return;\n\t\tif (seen.has(node)) return;\n\t\tseen.add(node);\n\n\t\tif (node.type === 'Element') {\n\t\t\t// Avoid duplicate traversal of attributes/children through openingElement/closingElement.\n\t\t\t// The Element node itself carries the data ESLint rules care about.\n\t\t\tdelete node.openingElement;\n\t\t\tdelete node.closingElement;\n\t\t}\n\n\t\tfor (const key of Object.keys(node)) {\n\t\t\tif (key === 'parent' || key === 'loc' || key === 'range') continue;\n\t\t\tconst value = node[key];\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const child of value) visit(child);\n\t\t\t} else if (value && typeof value === 'object') {\n\t\t\t\tvisit(value);\n\t\t\t}\n\t\t}\n\t};\n\n\tvisit(ast);\n}\n\n/**\n * Recursively walks the AST and ensures all nodes have range and loc properties\n * ESLint's scope analyzer requires these properties on ALL nodes\n */\nfunction ensureNodeProperties(node: any, code: string): void {\n\tif (!node || typeof node !== 'object') {\n\t\treturn;\n\t}\n\n\t// Ensure range property exists\n\tif (node.start !== undefined && node.end !== undefined && !node.range) {\n\t\tnode.range = [node.start, node.end];\n\t}\n\n\t// Ensure loc property exists\n\tif (!node.loc && node.start !== undefined && node.end !== undefined) {\n\t\tconst lines = code.split('\\n');\n\t\tlet currentPos = 0;\n\t\tlet startLine = 1;\n\t\tlet startColumn = 0;\n\t\tlet endLine = 1;\n\t\tlet endColumn = 0;\n\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst lineLength = lines[i].length + 1;\n\t\t\tif (currentPos + lineLength > node.start) {\n\t\t\t\tstartLine = i + 1;\n\t\t\t\tstartColumn = node.start - currentPos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentPos += lineLength;\n\t\t}\n\n\t\tcurrentPos = 0;\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst lineLength = lines[i].length + 1;\n\t\t\tif (currentPos + lineLength > node.end) {\n\t\t\t\tendLine = i + 1;\n\t\t\t\tendColumn = node.end - currentPos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentPos += lineLength;\n\t\t}\n\n\t\tnode.loc = {\n\t\t\tstart: { line: startLine, column: startColumn },\n\t\t\tend: { line: endLine, column: endColumn },\n\t\t};\n\t}\n\n\tfor (const key in node) {\n\t\tif (key === 'parent' || key === 'loc' || key === 'range') {\n\t\t\tcontinue; // Skip these to avoid infinite loops\n\t\t}\n\n\t\tconst value = node[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tvalue.forEach((child) => ensureNodeProperties(child, code));\n\t\t} else if (value && typeof value === 'object' && value.type) {\n\t\t\tensureNodeProperties(value, code);\n\t\t}\n\t}\n}\n\n/**\n * ESLint parser for Ripple (.ripple) files\n *\n * This parser uses Ripple's built-in compiler to parse .ripple files\n * and returns an ESTree-compatible AST for ESLint to analyze.\n */\nexport function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult {\n\ttry {\n\t\t// Dynamically import the Ripple compiler\n\t\t// We use dynamic import to avoid bundling the entire compiler\n\t\tconst rippleCompiler = requireRippleCompiler();\n\n\t\t// Parse the Ripple source code using the Ripple compiler\n\t\tconst ast = rippleCompiler.parse(code);\n\t\tif (!ast) throw new Error('Parser returned null or undefined AST');\n\n\t\t// Normalize for ESLint traversal (avoid duplicate node visits)\n\t\tnormalizeRippleAstForEslint(ast);\n\n\t\t// Recursively ensure all nodes have range and loc properties\n\t\tensureNodeProperties(ast, code);\n\n\t\t// Create a properly structured AST object ensuring all required properties exist\n\t\tconst result: any = {\n\t\t\ttype: ast.type || 'Program',\n\t\t\tstart: ast.start !== undefined ? ast.start : 0,\n\t\t\tend: ast.end !== undefined ? ast.end : code.length,\n\t\t\tloc: ast.loc || {\n\t\t\t\tstart: { line: 1, column: 0 },\n\t\t\t\tend: { line: code.split('\\n').length, column: 0 },\n\t\t\t},\n\t\t\trange: ast.range || [0, code.length],\n\t\t\tbody: ast.body || [],\n\t\t\tsourceType: ast.sourceType || 'module',\n\t\t\tcomments: ast.comments || [],\n\t\t\ttokens: ast.tokens || [],\n\t\t};\n\n\t\treturn {\n\t\t\tast: result,\n\t\t\tservices: {},\n\t\t\tvisitorKeys: undefined, // Use ESLint's default visitor keys\n\t\t};\n\t} catch (error: any) {\n\t\t// Transform Ripple parse errors to ESLint-compatible format\n\t\tthrow new SyntaxError(`Failed to parse Ripple file: ${error.message || error}`);\n\t}\n}\n\n/**\n * Legacy parse function for older ESLint versions\n */\nexport function parse(code: string, options?: Linter.ParserOptions): Program {\n\tconst result = parseForESLint(code, options);\n\treturn result.ast;\n}\n\n/**\n * Helper to require the Ripple compiler\n * This handles both CommonJS and ESM environments\n */\nfunction requireRippleCompiler(): any {\n\tconst globalRipple = (globalThis as any).__RIPPLE_COMPILER__;\n\tif (globalRipple && globalRipple.parse) {\n\t\treturn globalRipple;\n\t}\n\n\ttry {\n\t\t// Use createRequire to dynamically require the module\n\t\t// This works in both ESM and CommonJS contexts\n\t\tconst require = createRequire(import.meta.url);\n\t\tconst ripple = require('@tsrx/ripple');\n\n\t\tif (!ripple || !ripple.parse) {\n\t\t\tthrow new Error('Ripple compiler loaded but parse function not found.');\n\t\t}\n\n\t\t(globalThis as any).__RIPPLE_COMPILER__ = ripple;\n\n\t\treturn ripple;\n\t} catch (error: any) {\n\t\tthrow new Error(\n\t\t\t`Failed to load Ripple compiler: ${error.message}. ` +\n\t\t\t\t'Make sure the \"@tsrx/ripple\" package is installed as a peer dependency.',\n\t\t);\n\t}\n}\n\ndeclare global {\n\tvar __RIPPLE_COMPILER__: {\n\t\tparse: (source: string) => Program;\n\t\tcompile: (source: string, filename: string, options?: any) => any;\n\t};\n}\n\nexport default {\n\tparseForESLint,\n\tparse,\n};\n"],"mappings":";;;;;;;;;;AAkBA,SAAS,4BAA4B,KAAgB;CACpD,MAAM,uBAAO,IAAI,KAAU;CAC3B,MAAM,SAAS,SAAc;AAC5B,MAAI,CAAC,QAAQ,OAAO,SAAS,SAAU;AACvC,MAAI,KAAK,IAAI,KAAK,CAAE;AACpB,OAAK,IAAI,KAAK;AAEd,MAAI,KAAK,SAAS,WAAW;AAG5B,UAAO,KAAK;AACZ,UAAO,KAAK;;AAGb,OAAK,MAAM,OAAO,OAAO,KAAK,KAAK,EAAE;AACpC,OAAI,QAAQ,YAAY,QAAQ,SAAS,QAAQ,QAAS;GAC1D,MAAM,QAAQ,KAAK;AACnB,OAAI,MAAM,QAAQ,MAAM,CACvB,MAAK,MAAM,SAAS,MAAO,OAAM,MAAM;YAC7B,SAAS,OAAO,UAAU,SACpC,OAAM,MAAM;;;AAKf,OAAM,IAAI;;;;;;AAOX,SAAS,qBAAqB,MAAW,MAAoB;AAC5D,KAAI,CAAC,QAAQ,OAAO,SAAS,SAC5B;AAID,KAAI,KAAK,UAAU,UAAa,KAAK,QAAQ,UAAa,CAAC,KAAK,MAC/D,MAAK,QAAQ,CAA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AAQ;IAClB,OAAO,IAAI,UAAU,SAAY,IAAI,QAAQ;IAC7C,KAAK,IAAI,QAAQ,SAAY,IAAI,MAAM,KAAK;IAC5C,KAAK,IAAI,OAAO;KACf,OAAO;MAAE,MAAM;MAAG,QAAQ;MAAG;KAC7B,KAAK;MAAE,MAAM,KAAK,MAAM,KAAK,CAAC;MAAQ,QAAQ;MAAG;KACjD;IACD,OAAO,IAAI,SAAS,CAAC,GAAG,KAAK,OAAO;IACpC,MAAM,IAAI,QAAQ,EAAE;IACpB,YAAY,IAAI,cAAc;IAC9B,UAAU,IAAI,YAAY,EAAE;IAC5B,QAAQ,IAAI,UAAU,EAAE;IACxB;GAIA,UAAU,EAAE;GACZ,aAAa;GACb;UACO,OAAY;AAEpB,QAAM,IAAI,YAAY,gCAAgC,MAAM,WAAW,QAAQ;;;;;;AAOjF,SAAgB,MAAM,MAAc,SAAyC;AAE5E,QADe,eAAe,MAAM,QAAQ,CAC9B;;;;;;AAOf,SAAS,wBAA6B;CACrC,MAAM,eAAgB,WAAmB;AACzC,KAAI,gBAAgB,aAAa,MAChC,QAAO;AAGR,KAAI;EAIH,MAAM,SADU,cAAc,OAAO,KAAK,IAAI,CACvB,eAAe;AAEtC,MAAI,CAAC,UAAU,CAAC,OAAO,MACtB,OAAM,IAAI,MAAM,uDAAuD;AAGxE,EAAC,WAAmB,sBAAsB;AAE1C,SAAO;UACC,OAAY;AACpB,QAAM,IAAI,MACT,mCAAmC,MAAM,QAAQ,2EAEjD;;;AAWH,kBAAe;CACd;CACA;CACA"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { Program } from 'estree';\nimport type { Linter } from 'eslint';\nimport { createRequire } from 'module';\n\ninterface ParseResult {\n\tast: Program;\n\tservices?: Record<string, any>;\n\tscopeManager?: any;\n\tvisitorKeys?: Record<string, string[]>;\n}\n\n/**\n * The Ripple compiler's AST contains some redundant references (e.g. `Element.attributes`\n * and `Element.openingElement.attributes`) that are useful for formatters/source-maps.\n * ESLint's traverser will visit both paths and can trigger duplicate rule reports.\n *\n * For ESLint, we prune JSX wrapper nodes to keep a single traversal path.\n */\nfunction normalizeRippleAstForEslint(ast: any): void {\n\tconst seen = new Set<any>();\n\tconst visit = (node: any) => {\n\t\tif (!node || typeof node !== 'object') return;\n\t\tif (seen.has(node)) return;\n\t\tseen.add(node);\n\n\t\tif (node.type === 'Element') {\n\t\t\t// Avoid duplicate traversal of attributes/children through openingElement/closingElement.\n\t\t\t// The Element node itself carries the data ESLint rules care about.\n\t\t\tdelete node.openingElement;\n\t\t\tdelete node.closingElement;\n\t\t}\n\n\t\tfor (const key of Object.keys(node)) {\n\t\t\tif (key === 'parent' || key === 'loc' || key === 'range') continue;\n\t\t\tconst value = node[key];\n\t\t\tif (Array.isArray(value)) {\n\t\t\t\tfor (const child of value) visit(child);\n\t\t\t} else if (value && typeof value === 'object') {\n\t\t\t\tvisit(value);\n\t\t\t}\n\t\t}\n\t};\n\n\tvisit(ast);\n}\n\n/**\n * Recursively walks the AST and ensures all nodes have range and loc properties\n * ESLint's scope analyzer requires these properties on ALL nodes\n */\nfunction ensureNodeProperties(node: any, code: string): void {\n\tif (!node || typeof node !== 'object') {\n\t\treturn;\n\t}\n\n\t// Ensure range property exists\n\tif (node.start !== undefined && node.end !== undefined && !node.range) {\n\t\tnode.range = [node.start, node.end];\n\t}\n\n\t// Ensure loc property exists\n\tif (!node.loc && node.start !== undefined && node.end !== undefined) {\n\t\tconst lines = code.split('\\n');\n\t\tlet currentPos = 0;\n\t\tlet startLine = 1;\n\t\tlet startColumn = 0;\n\t\tlet endLine = 1;\n\t\tlet endColumn = 0;\n\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst lineLength = lines[i].length + 1;\n\t\t\tif (currentPos + lineLength > node.start) {\n\t\t\t\tstartLine = i + 1;\n\t\t\t\tstartColumn = node.start - currentPos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentPos += lineLength;\n\t\t}\n\n\t\tcurrentPos = 0;\n\t\tfor (let i = 0; i < lines.length; i++) {\n\t\t\tconst lineLength = lines[i].length + 1;\n\t\t\tif (currentPos + lineLength > node.end) {\n\t\t\t\tendLine = i + 1;\n\t\t\t\tendColumn = node.end - currentPos;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcurrentPos += lineLength;\n\t\t}\n\n\t\tnode.loc = {\n\t\t\tstart: { line: startLine, column: startColumn },\n\t\t\tend: { line: endLine, column: endColumn },\n\t\t};\n\t}\n\n\tfor (const key in node) {\n\t\tif (key === 'parent' || key === 'loc' || key === 'range') {\n\t\t\tcontinue; // Skip these to avoid infinite loops\n\t\t}\n\n\t\tconst value = node[key];\n\t\tif (Array.isArray(value)) {\n\t\t\tvalue.forEach((child) => ensureNodeProperties(child, code));\n\t\t} else if (value && typeof value === 'object' && value.type) {\n\t\t\tensureNodeProperties(value, code);\n\t\t}\n\t}\n}\n\n/**\n * ESLint parser for Ripple (.tsrx) files\n *\n * This parser uses Ripple's built-in compiler to parse .tsrx files\n * and returns an ESTree-compatible AST for ESLint to analyze.\n */\nexport function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult {\n\ttry {\n\t\t// Dynamically import the Ripple compiler\n\t\t// We use dynamic import to avoid bundling the entire compiler\n\t\tconst rippleCompiler = requireRippleCompiler();\n\n\t\t// Parse the Ripple source code using the Ripple compiler\n\t\tconst ast = rippleCompiler.parse(code);\n\t\tif (!ast) throw new Error('Parser returned null or undefined AST');\n\n\t\t// Normalize for ESLint traversal (avoid duplicate node visits)\n\t\tnormalizeRippleAstForEslint(ast);\n\n\t\t// Recursively ensure all nodes have range and loc properties\n\t\tensureNodeProperties(ast, code);\n\n\t\t// Create a properly structured AST object ensuring all required properties exist\n\t\tconst result: any = {\n\t\t\ttype: ast.type || 'Program',\n\t\t\tstart: ast.start !== undefined ? ast.start : 0,\n\t\t\tend: ast.end !== undefined ? ast.end : code.length,\n\t\t\tloc: ast.loc || {\n\t\t\t\tstart: { line: 1, column: 0 },\n\t\t\t\tend: { line: code.split('\\n').length, column: 0 },\n\t\t\t},\n\t\t\trange: ast.range || [0, code.length],\n\t\t\tbody: ast.body || [],\n\t\t\tsourceType: ast.sourceType || 'module',\n\t\t\tcomments: ast.comments || [],\n\t\t\ttokens: ast.tokens || [],\n\t\t};\n\n\t\treturn {\n\t\t\tast: result,\n\t\t\tservices: {},\n\t\t\tvisitorKeys: undefined, // Use ESLint's default visitor keys\n\t\t};\n\t} catch (error: any) {\n\t\t// Transform Ripple parse errors to ESLint-compatible format\n\t\tthrow new SyntaxError(`Failed to parse Ripple file: ${error.message || error}`);\n\t}\n}\n\n/**\n * Legacy parse function for older ESLint versions\n */\nexport function parse(code: string, options?: Linter.ParserOptions): Program {\n\tconst result = parseForESLint(code, options);\n\treturn result.ast;\n}\n\n/**\n * Helper to require the Ripple compiler\n * This handles both CommonJS and ESM environments\n */\nfunction requireRippleCompiler(): any {\n\tconst globalRipple = (globalThis as any).__RIPPLE_COMPILER__;\n\tif (globalRipple && globalRipple.parse) {\n\t\treturn globalRipple;\n\t}\n\n\ttry {\n\t\t// Use createRequire to dynamically require the module\n\t\t// This works in both ESM and CommonJS contexts\n\t\tconst require = createRequire(import.meta.url);\n\t\tconst ripple = require('@tsrx/ripple');\n\n\t\tif (!ripple || !ripple.parse) {\n\t\t\tthrow new Error('Ripple compiler loaded but parse function not found.');\n\t\t}\n\n\t\t(globalThis as any).__RIPPLE_COMPILER__ = ripple;\n\n\t\treturn ripple;\n\t} catch (error: any) {\n\t\tthrow new Error(\n\t\t\t`Failed to load Ripple compiler: ${error.message}. ` +\n\t\t\t\t'Make sure the \"@tsrx/ripple\" package is installed as a peer dependency.',\n\t\t);\n\t}\n}\n\ndeclare global {\n\tvar __RIPPLE_COMPILER__: {\n\t\tparse: (source: string) => Program;\n\t\tcompile: (source: string, filename: string, options?: any) => any;\n\t};\n}\n\nexport default {\n\tparseForESLint,\n\tparse,\n};\n"],"mappings":";;;;;;;;;;AAkBA,SAAS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;AAE5E,QADe,eAAe,MAAM,QAAQ,CAC9B;;;;;;AAOf,SAAS,wBAA6B;CACrC,MAAM,eAAgB,WAAmB;AACzC,KAAI,gBAAgB,aAAa,MAChC,QAAO;AAGR,KAAI;EAIH,MAAM,SADU,cAAc,OAAO,KAAK,IAAI,CACvB,eAAe;AAEtC,MAAI,CAAC,UAAU,CAAC,OAAO,MACtB,OAAM,IAAI,MAAM,uDAAuD;AAGxE,EAAC,WAAmB,sBAAsB;AAE1C,SAAO;UACC,OAAY;AACpB,QAAM,IAAI,MACT,mCAAmC,MAAM,QAAQ,2EAEjD;;;AAWH,kBAAe;CACd;CACA;CACA"}
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@ripple-ts/eslint-parser",
3
- "version": "0.3.17",
4
- "description": "ESLint parser for Ripple (.ripple files)",
3
+ "version": "0.3.19",
4
+ "description": "ESLint parser for Ripple (.tsrx files)",
5
5
  "type": "module",
6
- "main": "dist/index.js",
6
+ "main": "src/index.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/Ripple-TS/ripple.git",
@@ -41,13 +41,14 @@
41
41
  "@types/estree": "^1.0.8",
42
42
  "@types/node": "^24.3.0",
43
43
  "tsdown": "^0.20.3",
44
- "typescript": "^5.9.3",
45
- "ripple": "0.3.17"
44
+ "typescript": "^5.9.3"
46
45
  },
47
46
  "engines": {
48
47
  "node": ">=20.0.0"
49
48
  },
50
49
  "scripts": {
51
- "build": "tsdown"
50
+ "dist": "perl -pi -e 's/\"main\": \"src\\/index.ts\"/\"main\": \"dist\\/index.js\"/' package.json",
51
+ "src": "perl -pi -e 's/\"main\": \"dist\\/index.js\"/\"main\": \"src\\/index.ts\"/' package.json",
52
+ "build": "pnpm dist && tsdown && pnpm src || pnpm src"
52
53
  }
53
54
  }
package/src/index.ts ADDED
@@ -0,0 +1,209 @@
1
+ import type { Program } from 'estree';
2
+ import type { Linter } from 'eslint';
3
+ import { createRequire } from 'module';
4
+
5
+ interface ParseResult {
6
+ ast: Program;
7
+ services?: Record<string, any>;
8
+ scopeManager?: any;
9
+ visitorKeys?: Record<string, string[]>;
10
+ }
11
+
12
+ /**
13
+ * The Ripple compiler's AST contains some redundant references (e.g. `Element.attributes`
14
+ * and `Element.openingElement.attributes`) that are useful for formatters/source-maps.
15
+ * ESLint's traverser will visit both paths and can trigger duplicate rule reports.
16
+ *
17
+ * For ESLint, we prune JSX wrapper nodes to keep a single traversal path.
18
+ */
19
+ function normalizeRippleAstForEslint(ast: any): void {
20
+ const seen = new Set<any>();
21
+ const visit = (node: any) => {
22
+ if (!node || typeof node !== 'object') return;
23
+ if (seen.has(node)) return;
24
+ seen.add(node);
25
+
26
+ if (node.type === 'Element') {
27
+ // Avoid duplicate traversal of attributes/children through openingElement/closingElement.
28
+ // The Element node itself carries the data ESLint rules care about.
29
+ delete node.openingElement;
30
+ delete node.closingElement;
31
+ }
32
+
33
+ for (const key of Object.keys(node)) {
34
+ if (key === 'parent' || key === 'loc' || key === 'range') continue;
35
+ const value = node[key];
36
+ if (Array.isArray(value)) {
37
+ for (const child of value) visit(child);
38
+ } else if (value && typeof value === 'object') {
39
+ visit(value);
40
+ }
41
+ }
42
+ };
43
+
44
+ visit(ast);
45
+ }
46
+
47
+ /**
48
+ * Recursively walks the AST and ensures all nodes have range and loc properties
49
+ * ESLint's scope analyzer requires these properties on ALL nodes
50
+ */
51
+ function ensureNodeProperties(node: any, code: string): void {
52
+ if (!node || typeof node !== 'object') {
53
+ return;
54
+ }
55
+
56
+ // Ensure range property exists
57
+ if (node.start !== undefined && node.end !== undefined && !node.range) {
58
+ node.range = [node.start, node.end];
59
+ }
60
+
61
+ // Ensure loc property exists
62
+ if (!node.loc && node.start !== undefined && node.end !== undefined) {
63
+ const lines = code.split('\n');
64
+ let currentPos = 0;
65
+ let startLine = 1;
66
+ let startColumn = 0;
67
+ let endLine = 1;
68
+ let endColumn = 0;
69
+
70
+ for (let i = 0; i < lines.length; i++) {
71
+ const lineLength = lines[i].length + 1;
72
+ if (currentPos + lineLength > node.start) {
73
+ startLine = i + 1;
74
+ startColumn = node.start - currentPos;
75
+ break;
76
+ }
77
+ currentPos += lineLength;
78
+ }
79
+
80
+ currentPos = 0;
81
+ for (let i = 0; i < lines.length; i++) {
82
+ const lineLength = lines[i].length + 1;
83
+ if (currentPos + lineLength > node.end) {
84
+ endLine = i + 1;
85
+ endColumn = node.end - currentPos;
86
+ break;
87
+ }
88
+ currentPos += lineLength;
89
+ }
90
+
91
+ node.loc = {
92
+ start: { line: startLine, column: startColumn },
93
+ end: { line: endLine, column: endColumn },
94
+ };
95
+ }
96
+
97
+ for (const key in node) {
98
+ if (key === 'parent' || key === 'loc' || key === 'range') {
99
+ continue; // Skip these to avoid infinite loops
100
+ }
101
+
102
+ const value = node[key];
103
+ if (Array.isArray(value)) {
104
+ value.forEach((child) => ensureNodeProperties(child, code));
105
+ } else if (value && typeof value === 'object' && value.type) {
106
+ ensureNodeProperties(value, code);
107
+ }
108
+ }
109
+ }
110
+
111
+ /**
112
+ * ESLint parser for Ripple (.tsrx) files
113
+ *
114
+ * This parser uses Ripple's built-in compiler to parse .tsrx files
115
+ * and returns an ESTree-compatible AST for ESLint to analyze.
116
+ */
117
+ export function parseForESLint(code: string, options?: Linter.ParserOptions): ParseResult {
118
+ try {
119
+ // Dynamically import the Ripple compiler
120
+ // We use dynamic import to avoid bundling the entire compiler
121
+ const rippleCompiler = requireRippleCompiler();
122
+
123
+ // Parse the Ripple source code using the Ripple compiler
124
+ const ast = rippleCompiler.parse(code);
125
+ if (!ast) throw new Error('Parser returned null or undefined AST');
126
+
127
+ // Normalize for ESLint traversal (avoid duplicate node visits)
128
+ normalizeRippleAstForEslint(ast);
129
+
130
+ // Recursively ensure all nodes have range and loc properties
131
+ ensureNodeProperties(ast, code);
132
+
133
+ // Create a properly structured AST object ensuring all required properties exist
134
+ const result: any = {
135
+ type: ast.type || 'Program',
136
+ start: ast.start !== undefined ? ast.start : 0,
137
+ end: ast.end !== undefined ? ast.end : code.length,
138
+ loc: ast.loc || {
139
+ start: { line: 1, column: 0 },
140
+ end: { line: code.split('\n').length, column: 0 },
141
+ },
142
+ range: ast.range || [0, code.length],
143
+ body: ast.body || [],
144
+ sourceType: ast.sourceType || 'module',
145
+ comments: ast.comments || [],
146
+ tokens: ast.tokens || [],
147
+ };
148
+
149
+ return {
150
+ ast: result,
151
+ services: {},
152
+ visitorKeys: undefined, // Use ESLint's default visitor keys
153
+ };
154
+ } catch (error: any) {
155
+ // Transform Ripple parse errors to ESLint-compatible format
156
+ throw new SyntaxError(`Failed to parse Ripple file: ${error.message || error}`);
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Legacy parse function for older ESLint versions
162
+ */
163
+ export function parse(code: string, options?: Linter.ParserOptions): Program {
164
+ const result = parseForESLint(code, options);
165
+ return result.ast;
166
+ }
167
+
168
+ /**
169
+ * Helper to require the Ripple compiler
170
+ * This handles both CommonJS and ESM environments
171
+ */
172
+ function requireRippleCompiler(): any {
173
+ const globalRipple = (globalThis as any).__RIPPLE_COMPILER__;
174
+ if (globalRipple && globalRipple.parse) {
175
+ return globalRipple;
176
+ }
177
+
178
+ try {
179
+ // Use createRequire to dynamically require the module
180
+ // This works in both ESM and CommonJS contexts
181
+ const require = createRequire(import.meta.url);
182
+ const ripple = require('@tsrx/ripple');
183
+
184
+ if (!ripple || !ripple.parse) {
185
+ throw new Error('Ripple compiler loaded but parse function not found.');
186
+ }
187
+
188
+ (globalThis as any).__RIPPLE_COMPILER__ = ripple;
189
+
190
+ return ripple;
191
+ } catch (error: any) {
192
+ throw new Error(
193
+ `Failed to load Ripple compiler: ${error.message}. ` +
194
+ 'Make sure the "@tsrx/ripple" package is installed as a peer dependency.',
195
+ );
196
+ }
197
+ }
198
+
199
+ declare global {
200
+ var __RIPPLE_COMPILER__: {
201
+ parse: (source: string) => Program;
202
+ compile: (source: string, filename: string, options?: any) => any;
203
+ };
204
+ }
205
+
206
+ export default {
207
+ parseForESLint,
208
+ parse,
209
+ };