@cordova/eslint-config

中文文档
6.0.1发布于 2026/02/18Apache-2.0CommonJS近 30 天下载 8.1万

Cordova ESLint Config

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Reference
  4. @cordova/eslint-config/node (or simply @cordova )
  5. @cordova/eslint-config/node-tests
  6. @cordova/eslint-config/browser
  7. @cordova/eslint-config/browser-tests

@cordova/eslint-config

NPM

Node CI Release Audit codecov.io

This repository centralizes the ESLint configuration used for Cordova's development, specifically repositories that start with apache/cordova-.

Installation

@cordova/eslint-config comes with all plugins configs and even eslint itself. So all you need to do to get started is:

npm i -D @cordova/eslint-config

Usage

# In package.json
{
  "scripts": {
    "lint": "eslint"
  }
}
// In eslint.config.js
const { defineConfig, globalIgnores } = require('eslint/config');
const nodeConfig = require('@cordova/eslint-config/node');
const nodeTestConfig = require('@cordova/eslint-config/node-tests');
const browserConfig = require('@cordova/eslint-config/browser');

module.exports = defineConfig([
    globalIgnores([
        // Add files or folders to ignore...
        // For example: exclude everything in the "coverage" directory.
        'coverage'
    ]),

    // Node Linting
    ...nodeConfig.map(config => ({
        files: [
            // Add files or folders to check...
            // For example: include everything in the "lib" directory.
            // By default, ESLint lints files with extensions .js, .mjs & .cjs.
            'lib'
        ],

        // Spread each shared config to preserve its settings while extending or overriding specific properties
        ...config
    })),

    // Node Test Linting
    ...nodeTestConfig.map(config => ({
        // Add files or folders to check...
        // For example: include everything in the "spec" directory.
        // By default, ESLint lints files with extensions .js, .mjs & .cjs.
        files: [
            'spec'
        ],

        // Spread each shared config to preserve its settings while extending or overriding specific properties
        ...config,

        // Overriding Rules
        rules: {
            // Make sure the original rules are applied
            ...(config.rules || {}),

            // Then append or update rules
            'prefer-promise-reject-errors': 'off'
        }
    })),

    // Browser Linting
    ...browserConfig.map(config => ({
        files: [
            // Add files or folders to check...
            // For Example: Platforms usuall has "cordova-js-src" that comiles down into a cordova.js file to runs in the app's WebView.
            'cordova-js-src'
        ],

        // Spread each shared config to preserve its settings while extending or overriding specific properties
        ...config,

        // Overriding Language Options
        languageOptions: {

            // Make sure the original languageOptions are applied if existing
            ...(config?.languageOptions || {}),

            // Overriding Global
            globals: {
                // Make sure the original languageOptions.globals are applied
                ...(config.languageOptions?.globals || {})

                // Then append or update globals
                require: 'readonly',
                module: 'readonly',
            }
        }
    }))
]);

Reference

This package exposes the following shareable ESLint configurations:

@cordova/eslint-config/node (or simply @cordova)

For linting scripts intended to be run with Node.js.

@cordova/eslint-config/node-tests

For linting Jasmine tests of Cordova's Node.js scripts.

@cordova/eslint-config/browser

For linting cordova-style CommonJS modules intended to be run in the browser (before they are bundled).

@cordova/eslint-config/browser-tests

For linting Jasmine tests of Cordova's browser code.

版本与发布记录

@cordova/eslint-config 共发布 8 个版本,首次发布于 2019/11/09;过去 12 个月发布了 1 个版本。

版本发布日期距今
6.0.1latest2026/02/188 个月前
6.0.02025/07/251.3 年前
5.1.02024/03/272 年前
5.0.02023/01/183 年前
4.0.02021/10/315 年前
3.0.02020/03/266 年前

关于 @cordova/eslint-config 的常见问题

@cordova/eslint-config 是什么?

Cordova ESLint Config

如何安装 @cordova/eslint-config?

在项目目录运行 npm install @cordova/eslint-config,或使用 pnpm add / yarn add / bun add。

@cordova/eslint-config 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/cordova__eslint-config 是否存在。

@cordova/eslint-config 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cordova/eslint-config 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.9.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cordova/eslint-config 可以商用吗?

@cordova/eslint-config 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cordova/eslint-config 的下载量有多少?

根据 npm 官方下载统计,@cordova/eslint-config 在 2026/10/11 – 2026/11/09 这 30 天内被下载 81,376 次,日均约 2,713 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cordova/eslint-config 还在维护吗?

最新版本 6.0.1 发布于 2026/02/18(8 个月前);至今共发布 8 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/11/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。