sitegeist/fluid-components-linter

基于指定规则集验证 fluid 组件的工具

1.0.4 2023-06-08 10:58 UTC

README

CLI 工具,根据特定的代码质量规则集验证您的 Fluid 组件

特性

  • 检查基本的 Fluid 语法
  • 检查组件结构是否正确(例如,组件 ViewHelpers 的正确嵌套)
  • 强制执行命名方案和参数名称的最小/最大长度
  • 限制每个组件的参数数量(这将导致组件更加简单)
  • 强制执行参数描述
  • 强制存在用于 Fluid Styleguide 的 markdown 文档和固定文件
  • 规范化参数类型中命名空间的语言
  • 鼓励使用严格的数据类型而不是通用的 arrayobject
  • 如果参数名称包含类似 linkimage 的提示,则建议使用正确的类型
  • 强制使用组件前缀和 class 参数
  • 强制某些 ViewHelpers 不能在组件内部使用
  • 强制 content 参数始终被 <f:format.raw> 包围

入门

要使用 linter,请通过 composer 将此包作为开发依赖项引入

composer req --dev sitegeist/fluid-components-linter

此包提供二进制文件 fclint,可用于验证单个组件文件以及包含组件文件的整个目录结构。

fclint lint Resources/Private/Components/

为了便于使用,您可能想在项目中定义自定义 composer 命令

composer.json

{
    ...

    "scripts": {
        "lint:components": "fclint lint Resources/Private/Components/"
    }
}

然后只需调用

composer lint:components

(按需,在 git 钩子中,在您的 CI 中...)

自定义规则集

如果您想修改代码质量规则集,则可以覆盖在 default.fclint.json 中预定义的规则

fclint lint -c ./myRules.fclint.json Resources/Private/Components/

为了方便起见,当前工作目录中名为 .fclint.json 的文件将被自动拾取,无需使用 -c 指定。

您的调整后的配置将与选定的配置预设合并,因此您只需指定要更改的规则。要更改以下默认规则

  • 忽略名为 Template/ 的文件夹中的所有组件
  • 如果存在固定文件,则不需要 markdown 文档文件
  • 参数名称长度限制为 30 个字符(默认为 40)

您将使用以下配置文件

.fclint.json

{
    "files": {
        "ignorePatterns": [
            "**/Template/**"
        ]
    },
    "component": {
        "requireDocumentationWithFixtureFile": {
            "check": false
        }
    },
    "params": {
        "nameLength": {
            "max": 30
        }
    }
}

命令行选项

有一些命令行选项可以指定

$ fclint lint --help
Description:
Validates fluid components based on a specified ruleset

Usage:
lint [options] [--] <paths>...

Arguments:
paths                        Component files that should be included

Options:
-e, --extension[=EXTENSION]  Component file extension [default: ".html"]
-p, --preset[=PRESET]        Name of configuration preset [default: false]
-c, --config[=CONFIG]        Path to custom configuration file (.fclint.json in the current working directory will be picked up automatically) [default: false]
    --severity[=SEVERITY]    Minimum severity, all issues below this severity will be skipped. Possible values: info, minor, major, critical, blocker [default: "info"]
-i, --ignore[=IGNORE]        Glob pattern that defines which files should be skipped (multiple values allowed)
    --json                   Output results as json (compatible to codeclimate spec)

支持和讨论

如果您有任何问题,需要支持或想要讨论 TYPO3 中的组件,请随时加入 #ext-fluid_components