npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@longzai-intelligence-arkts/eslint-parser-arkts

v0.0.15

Published

ArkTS ESLint Parser - 将 .ets 文件预处理为标准 TypeScript

Readme

@apex-energy-watch/eslint-parser-arkts

ArkTS ESLint Parser - 将 .ets 文件预处理为标准 TypeScript。

安装

bun add -D @apex-energy-watch/eslint-parser-arkts @typescript-eslint/parser

用法

ESLint Flat Config

import arkts from '@apex-energy-watch/eslint-plugin-arkts';
import arktsParser from '@apex-energy-watch/eslint-parser-arkts';

export default [
  {
    files: ['**/*.ets'],
    plugins: { arkts },
    languageOptions: {
      parser: arktsParser,
      parserOptions: {
        sdkPath: '/path/to/openharmony/sdk',
      },
    },
    rules: {
      ...arkts.configs.recommended.rules,
    },
  },
];

独立使用

import { parseForESLint, meta } from '@apex-energy-watch/eslint-parser-arkts';

const code = `
@Component
struct MyComponent {
  build() {
    Column() {
      Text('hello')
    }
  }
}
`;

const result = parseForESLint(code, { filePath: 'test.ets' });
console.log(result.ast);

API

parseForESLint(code, options)

ESLint Parser 标准接口。

参数:

  • code: string - 源码内容
  • options: ArkTSParserOptions - Parser 选项
    • filePath?: string - 文件路径(用于判断是否为 .ets 文件)
    • sdkPath?: string - OpenHarmony SDK 路径
    • 其他 @typescript-eslint/parser 支持的选项

返回:

  • ast - ESTree AST
  • services - TypeScript 服务(program、typeChecker)
  • scopeManager - 作用域管理器
  • visitorKeys - 访问者键

parse(code, options)

简化接口,只返回 AST。

meta

Parser 元信息:

{
  name: '@apex-energy-watch/eslint-parser-arkts',
  version: '0.1.0'
}

工作原理

  1. 检测 .ets 文件扩展名
  2. 将 ArkTS 特有语法预处理为标准 TypeScript:
    • struct → class
    • $$this → __ets_this
    • 移除声明式装饰器(@Builder 等)
    • 清空声明式 UI 块内容
  3. 委托 @typescript-eslint/parser 解析预处理后的代码
  4. 返回 AST 和类型检查服务

所有预处理都是等长替换,确保行列号与原始代码完全对应。

文档

依赖

  • @typescript-eslint/parser - 实际的 TypeScript 解析
  • @typescript-eslint/types - 类型定义

License

MIT