Coder Social home page Coder Social logo

eslint-config's Introduction

@uni-helper/eslint-config

适用于 uni-app 的 Anthony's ESLint 配置预设

安装

pnpm i -D eslint @uni-helper/eslint-config

使用

配置文件

With CJS:

// eslint.config.js
const uni = require('@uni-helper/eslint-config')

module.exports = uni()

在 package.json 中添加 script

{
  "scripts": {
    "lint": "eslint .",
    "lint:fix": "eslint . --fix"
  }
}

Warning

uni-app 暂不支持使用 "type": "module"

With ESM:

package.json 中设置 "type": "module"

{
  "type": "module"
}

设置以下 eslint.config.js

import uni from '@uni-helper/eslint-config'

export default uni()

VS Code 自动修复

安装 VS Code ESLint 扩展

将以下设置添加到您的 .vscode/settings.json 中:

{
  // Enable the ESlint flat config support
  "eslint.experimental.useFlatConfig": true,

  // Disable the default formatter, use eslint instead
  "prettier.enable": false,
  "editor.formatOnSave": false,

  // Auto fix
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit",
    "source.organizeImports": "never"
  },

  // Silent the stylistic rules in you IDE, but still auto fix them
  "eslint.rules.customizations": [
    { "rule": "style/*", "severity": "off" },
    { "rule": "*-indent", "severity": "off" },
    { "rule": "*-spacing", "severity": "off" },
    { "rule": "*-spaces", "severity": "off" },
    { "rule": "*-order", "severity": "off" },
    { "rule": "*-dangle", "severity": "off" },
    { "rule": "*-newline", "severity": "off" },
    { "rule": "*quotes", "severity": "off" },
    { "rule": "*semi", "severity": "off" }
  ],

  // Enable eslint for all supported languages
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "vue",
    "html",
    "markdown",
    "json",
    "jsonc",
    "yaml"
  ]
}

定制化

通常你只需要导入 uni-helper 预设:

// eslint.config.js
const uni = require('@uni-helper/eslint-config')

module.exports = uni()

如果你想调整 uni-helper 预设可以这样做:

// eslint.config.js
const uni = require('@uni-helper/eslint-config')

module.exports = uni({
  // 启用 stylistic 格式化规则
  // stylistic: true,

  // 自定义 stylistic 规则
  stylistic: {
    indent: 2, // 4, or 'tab'
    quotes: 'single', // or 'double'
  },

  // TypeScript 和 Vue 是自动检测的,你也可以显式启用它们:
  typescript: true,
  vue: true,

  // 禁用 json 和 yaml 支持
  jsonc: false,
  yaml: false,

  // 在 Flat 配置中不再支持 `.eslintignore`,请使用 `ignores` 代替
  ignores: [
    './fixtures',
    // ...globs
  ]
})

你还可以自定义任意规则以覆盖默认规则:

// eslint.config.js
const uni = require('@uni-helper/eslint-config')

module.exports = uni(
  {
    // 为 uniHelper 配置规则
  },

  // 从第二个参数开始,为 ESLint Flat 配置,它可以存在多个
  {
    files: ['**/*.ts'],
    rules: {},
  },
  {
    rules: {},
  },
)

高级

要了解更多配置及选项,查看 @antfu/eslint-config 的文档,

eslint-config's People

Contributors

kejunmao avatar ares-chang avatar flippedround avatar renovate[bot] avatar

Stargazers

 avatar Filip Vanden Eynde avatar Vanisper avatar viarotel avatar  avatar Curie avatar  avatar

Watchers

 avatar

eslint-config's Issues

feat: fully support nvue

对问题的清晰和简明的描述

  • 基本支持
  • renderjs
  • template
  • 多 script lint fix 支持

推荐的解决方案

基于 eslint-plugin-vue 改一个出来? 但是这样又会多一套配置,也许扩展一下能支持就好了

替代方案

No response

额外上下文

看了下 vue-eslint-parser 大于 2 个 script node 直接只取第一个

检查

  • 遵循我们的 行为准则
  • 检查是否已经有一个要求相同功能的问题,以避免重复创建。

升级模块依赖版本

对问题的清晰和简明的描述

截至目前, @antfu/eslint-config 的版本更新到了2.21.2 ,对应的eslint版本也升级到了9.5.0(虽然是补丁版:npm:[email protected])。
而本仓库已经6个月未更新了......

推荐的解决方案

更新并适配@antfu/eslint-config 和eslint的新版本。

替代方案

No response

额外上下文

https://github.com/antfu/eslint-config

检查

  • 遵循我们的 行为准则
  • 检查是否已经有一个要求相同功能的问题,以避免重复创建。

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update actions/setup-node action to v4
  • chore(deps): update dependency eslint to v9
  • chore(deps): update dependency execa to v9
  • chore(deps): update dependency vitest to v2
  • chore(deps): update pnpm to v9

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v3
  • pnpm/action-setup v2
  • actions/setup-node v3
npm
package.json
  • @antfu/eslint-config ^2.1.1
  • local-pkg ^0.5.0
  • @types/fs-extra ^11.0.4
  • @types/node ^20.10.0
  • bumpp ^9.2.0
  • eslint ^8.54.0
  • esno ^4.0.0
  • execa ^8.0.1
  • fast-glob ^3.3.2
  • fs-extra ^11.2.0
  • typescript ^5.3.2
  • unbuild ^2.0.0
  • vite ^5.0.3
  • vitest ^0.34.6
  • pnpm 8.11.0

  • Check this box to trigger a request for Renovate to run again on this repository

webstorm 上面报错,不知道是不是我的个例

描述问题

Error: Invalid Options:
- Unknown options: reportUnusedDisableDirectives
- 'reportUnusedDisableDirectives' has been removed. Please use the 'overrideConfig.linterOptions.reportUnusedDisableDirectives' option instead.
image

复现

image image

系统信息

System:
    OS: macOS 12.6.5
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
    Memory: 172.86 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.0 - ~/.nvm/versions/node/v16.17.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v16.17.0/bin/yarn
    npm: 8.15.0 - ~/.nvm/versions/node/v16.17.0/bin/npm
  Browsers:
    Chrome: 120.0.6099.109
    Firefox: 63.0.3

使用的包管理器

yarn

核对

  • 遵循我们的 行为准则
  • 检查是否已经有一个报告相同错误的问题,以避免重复创建。
  • 这是一个具体的错误。请开启 GitHub 讨论你的疑问。
  • 所提供的复现是这个问题的 最小复现

组件命名为什么强制调整为 kebab-case 模式呢?

对问题的清晰和简明的描述

为什么要强制锁定组件命名模式呢?我并不是很能接受自定义组件 kebab-case 写法。

'vue/component-name-in-template-casing': ['error', 'kebab-case', {
registeredComponentsOnly: false,
}],

这个地方如果不设置的话,antfu 默认应该是 registeredComponentsOnly: true 仅检查已注册的组件 ,应该是不会影响到 uni-app 原生标签的。

推荐的解决方案

虽然可以自定义修改规则,但我觉得保持默认是最好的选择。

ps: 是不是最好能提供一下怎么自定义规则文档,我刚刚在第一个参数里直接写了规则,ts 也没有报错,我就以为配置成功了,但是半天不生效,所以我去看了源码好像不是这样用的 :)。

替代方案

image

额外上下文

No response

检查

  • 遵循我们的 行为准则
  • 检查是否已经有一个要求相同功能的问题,以避免重复创建。

config 无法添加 ignores 属性

Describe the bug

image image

Reproduction

const uni = require('@uni-helper/eslint-config')
const unocss = require('@unocss/eslint-plugin')

module.exports = uni(
  {
    overrides: {
      uni: {
        'vue/component-name-in-template-casing': ['error', 'PascalCase'],
      },
    },
    ignores: [
      './src/**/*.js',
    ],
  },
  unocss.configs.flat,
)

"eslint": "^8.56.0",
"@uni-helper/eslint-config": "^0.0.6",
"@unocss/eslint-config": "^0.58.3",

System Info

System:
    OS: macOS 12.6.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 356.16 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/Library/Caches/fnm_multishells/4880_1706113613238/bin/node
    Yarn: 1.22.21 - ~/Library/Caches/fnm_multishells/4880_1706113613238/bin/yarn
    npm: 10.2.3 - ~/Library/Caches/fnm_multishells/4880_1706113613238/bin/npm
  Browsers:
    Chrome: 123.0.6312.107
    Safari: 16.1

Used Package Manager

yarn

Validations

  • Follow our Code of Conduct
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible of the bug.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.