Linting 配置

我发现默认的 linting 配置与预期工作方式存在显著差异。

默认配置将 eslint-config-discourse 包安装为开发依赖项:
https://www.npmjs.com/package/eslint-config-discourse

然而,当我查看源代码时,在 https://github.com/discourse/eslint-config-discourse 该存储库被重定向到 @discourse/lint-configs;它也是 eslint-config-discourse monorepo 下的一个包。我认为包含的测试 eslint-config-discourse 应该是一个包装器,但它并没有按预期工作,至少根据我的经验是这样:

默认 Linting 配置

  1. 使用 discourse_theme new 命令创建一个新主题。
  2. 查看生成的 linting 配置:
    a. .eslintrc
    {
      "extends": "eslint-config-discourse",
      "globals": {
        "settings": "readonly",
        "themePrefix": "readonly"
      }
    }
    
    b. .template-lintrc.js
    module.exports = {
      plugins: ["ember-template-lint-plugin-discourse"],
      extends: "discourse:recommended",
    };
    
    c. package.json
    {
      "license": "MIT",
      "devDependencies": {
        "eslint-config-discourse": "latest"
      }
    }
    
  3. 在包上运行 Prettier,它会抱怨 *.gjs 文件:
    yarn prettier --check --write "{common,javascripts,desktop,mobile,test,scss}/**/*.{js,gjs,es6,scss}"
    
    错误:无法推断文件 ... .gjs 的解析器

直接配置 @discourse/lint-configs

https://www.npmjs.com/package/@discourse/lint-configs

  1. 运行 yarn remove -D eslint-config-discourse 卸载该包。
  2. 运行 yarn add -D @discourse/lint-configs 作为开发依赖项安装
  3. 按照说明创建 linting 配置文件:
    a. 将 .eslintrc 文件替换为 .eslintrc.cjs
    module.exports = require("@discourse/lint-configs/eslint-theme");
    
    b. 添加 .prettierrc.cjs 文件:
    module.exports = require("@discourse/lint-configs/prettier");
    
    c. 将 .template-lintrc.js 文件替换为 .template-lintrc.cjs
    module.exports = require("@discourse/lint-configs/template-lint");
    
  4. 再次尝试运行 Prettier,并观察它是否能正常工作而没有错误:
    $ yarn prettier --check --write "{common,javascripts,desktop,mobile,test,scss}/**/*.{js,gjs,es6,scss}"
    正在检查格式...
    所有匹配的文件都使用 Prettier 代码风格!
    ✨  完成,耗时 0.46 秒。
    

那么,我是否应该认为 discourse_theme CLI 已过时,并且以后应该在我的项目中改用 @discourse/lint-configs 选项?

不。相信它。提交到你的仓库,当你的 linting 命令失败时,看看它们。

1 个赞

你好 @pfaffman

我在我的仓库上做了一个小测试。虽然两种情况都通过了完成,但默认配置会为 GJS 文件生成一个错误,并且该文件未被扫描。

在第二种方法中,GJS 文件被识别并成功 linted。

请比较 main 分支的操作和 linting 分支的操作;我只在 linting 分支中引入了第二种选择的配置:

main:

\u003chttps://github.com/gormus/discourse-filtered-topic-lists/actions/runs/10325377606/job/28586838134?pr=1#step:6:19\u003e

linting:

\u003chttps://github.com/gormus/discourse-filtered-topic-lists/actions/runs/10333473217/job/28605865585?pr=3#step:6:17\u003e

不应该。最新版本的 discourse_theme CLI 会克隆 GitHub - discourse/discourse-theme-skeleton: Template for Discourse themes 并根据您的输入进行调整。它使用 @discourse/lint-configs

更新说明在这里:

4 个赞

谢谢,就是这个。现在我可以获取版本(以前我没有获取版本):

discourse_theme --version
2.1.2

…以及更新的命令列表:

discourse_theme --help
Usage: discourse_theme COMMAND [DIR] [OPTIONS]

Commands:
  new DIR               - 在指定目录中创建一个新主题。
  download DIR          - 从服务器下载主题并将其存储在指定目录中。
  upload DIR            - 将指定目录中的主题上传到 Discourse。
  watch DIR             - 监视指定目录中的主题并与 Discourse 同步任何更改。
  rspec DIR [OPTIONS]   - 在指定目录中运行 RSpec 测试。可以使用本地 Discourse 存储库或 Docker 容器运行测试。
    --headful           - 以 headful 模式运行 RSpec 系统类型测试。适用于两种模式。

    如果指定目录已配置为在 Docker 容器中运行,则支持其他选项。
    --rebuild           - 强制重建 Docker 容器。
    --verbose           - 以详细模式运行命令以准备 Docker 容器。

Global Options:
  --reset               - 重置指定目录的配置。

当然,生成的骨架也更新了。 :smiley:

5 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.