sinemacula/coding-standards 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sinemacula/coding-standards

Composer 安装命令:

composer require sinemacula/coding-standards

包简介

Centralized coding standards, static analysis configurations, and code quality tooling for all Sine Macula repositories.

README 文档

README

Latest Stable Version npm Version Maintainability Code Coverage Total Downloads

Centralized coding standards, static analysis configurations, and code quality tooling for all Sine Macula repositories.

This package ships config files only - no runtime dependencies. Consuming projects install the tools themselves.

Installation

Composer (PHP-side: PHP CS Fixer, PHPStan, PHPCS)

composer require --dev sinemacula/coding-standards

npm (JS-side: Biome, Knip)

npm install --save-dev @sinemacula/coding-standards

The npm package ships only the static configs (js/, markdown/, yaml/, shell/, security/). The PHP autoloaded code lives in the Composer package.

Usage

Each consuming project creates thin wrapper files at its root that reference the shared configs.

PHP CS Fixer

Create a .php-cs-fixer.dist.php at your project root:

<?php

use SineMacula\CodingStandards\PhpCsFixerConfig;

return PhpCsFixerConfig::make([
    __DIR__ . '/src',
    __DIR__ . '/tests',
]);

You can pass rule overrides as a second argument:

return PhpCsFixerConfig::make(
    [__DIR__ . '/src', __DIR__ . '/tests'],
    ['strict_comparison' => false],
);

PHPCS

The SineMacula coding standard is auto-discovered via the phpcodesniffer-standard composer type. Create a phpcs.xml at your project root:

<?xml version="1.0"?>
<ruleset name="Project">
    <rule ref="SineMacula"/>
    <file>src</file>
    <file>tests</file>
</ruleset>

PHPStan

The shared PHPStan configs are auto-included via the extra.phpstan.includes section in composer.json. Your project's phpstan.neon only needs project-specific settings:

parameters:
    level: 8
    paths:
        - src
        - tests

Laravel projects

For Laravel projects, also install sinemacula/coding-standards-laravel and reference its SineMaculaLaravel PHPCS standard (which includes this one) in place of SineMacula. It adds the Laravel-specific sniffs and PHPStan rules; see that package's README for setup.

Biome (JavaScript / TypeScript)

After installing the npm package, extend the shared Biome config from your project's biome.json (or .qlty/configs/biome.json when wired through Qlty):

{
    "$schema": "https://biomejs.dev/schemas/2.0.0/schema.json",
    "root": true,
    "extends": ["@sinemacula/coding-standards/js/biome.json"],
    "files": {
        "ignoreUnknown": true,
        "includes": ["**", "!**/node_modules/**", "!**/vendor/**"]
    }
}

extends paths are resolved through normal Node module lookup, so the package only needs to be installed (no path math against node_modules/ required). Project-specific files.includes and files.excludes stay in the consumer config.

ESLint (JavaScript / TypeScript)

ESLint runs alongside Biome, not in place of it. Biome keeps owning formatting and the fast syntactic lint; ESLint adds only the two things Biome structurally cannot express: this package's custom structural rules and the opt-in type-aware rules (the curated typescript-eslint set plus the type-driven custom rules). Add the linter, the typescript-eslint tooling, and this package to your dev dependencies:

npm install --save-dev eslint typescript typescript-eslint eslint-plugin-jsdoc @sinemacula/coding-standards

The package exposes two flat-config entry points:

  • @sinemacula/coding-standards/js/eslint - the base layer of syntax-only custom rules; needs no tsconfig, so it stays cheap and runs anywhere Biome runs.
  • @sinemacula/coding-standards/js/eslint/type-checked - the opt-in type-aware layer. It includes the base layer and adds the cross-file / type-driven rules, so it needs a consumer tsconfig; use it in place of the base layer where one exists.

Create an eslint.config.js (or .qlty/configs/eslint.config.js when wired through Qlty) that spreads the layer you want. Without a tsconfig, use the base layer:

import sm from '@sinemacula/coding-standards/js/eslint';

export default [...sm];

Where a tsconfig exists, use the type-aware layer instead (it already carries the base rules):

import typeChecked from '@sinemacula/coding-standards/js/eslint/type-checked';

export default [...typeChecked];

When wiring ESLint through Qlty, the shared eslint plugin sandbox installs only eslint, jest, and prettier by default, so the flat config's imports of this package and typescript-eslint fail to resolve. Widen the install filter in your .qlty/qlty.toml so the sandbox carries them (this repository's source.toml exports the same override, but source-exported plugin definitions do not reliably propagate, so mirror it consumer-side):

[plugins.definitions.eslint]
package_filters = ["@sinemacula/coding-standards", "typescript-eslint", "@typescript-eslint", "eslint-plugin-jsdoc"]

Knip (JavaScript / TypeScript)

{
    "$schema": "https://unpkg.com/knip@6/schema.json",
    "extends": ["@sinemacula/coding-standards/js/knip.json"]
}

Qlty

Reference this repository as a source in your project's .qlty/qlty.toml, pinning tag to the latest release:

[[source]]
name = "sinemacula"
repository = "https://github.com/sinemacula/coding-standards"
tag = "<version>"

What's Included

Path Tool Description
src/PhpCsFixerConfig.php PHP CS Fixer Factory class for building PHP CS Fixer configurations
php/.php-cs-fixer.rules.php PHP CS Fixer Shared rules array (PSR-12 base + org conventions)
SineMacula/ruleset.xml PHPCS Auto-discovered coding standard (PSR-12 + exclusions)
php/phpstan-base.neon PHPStan Base config (org-wide ignored errors + settings)
js/biome.json Biome JavaScript / TypeScript formatter + linter rules
js/knip.json Knip Unused-export detection rules
js/eslint/ ESLint Custom structural + type-aware rules; runs with Biome
markdown/.markdownlint.json markdownlint Markdown linting rules
yaml/.yamllint.yaml yamllint YAML linting rules
shell/.shellcheckrc ShellCheck Shell script linting rules
security/.gitleaks.toml Gitleaks Secret-detection ruleset
editorconfig/.editorconfig-checker.json editorconfig-checker Disables only the max-line-length check

Rules

These are the custom rules this package enforces on top of PSR-12. A deliberate exception can be bypassed with the native directive - // phpcs:ignore <code> for a sniff, @phpstan-ignore <identifier> for a rule, // eslint-disable-next-line <rule> for an ESLint rule.

PHPCS sniffs

Sniff Enforces
SineMacula.Attributes.DisallowToolingAttribute No IDE/tooling attributes (e.g. JetBrains\PhpStorm).
SineMacula.Classes.RequireFinalClass Concrete classes must be final or abstract (@inheritable opts out).
SineMacula.Classes.RequireReadonlyPublicProperty Public properties (declared or promoted) must be readonly.
SineMacula.Commenting.CommentLineLength Standalone comment lines must not exceed 80 chars (FQCN/URL exempt).
SineMacula.Commenting.ConsistentEnumCaseComments Enum case docs are all-or-nothing within an enum.
SineMacula.Commenting.RequireConstantComment Every class/interface/enum/trait constant needs a doc comment.
SineMacula.Commenting.RequireCopyrightTag Class/interface/enum/trait docblocks must carry an @copyright tag.
SineMacula.Commenting.RequireNonPromotedParameterComment Plain params mixed with promoted ones need a comment.
SineMacula.Commenting.RequirePromotedPropertyComment Every constructor-promoted property needs a doc comment.
SineMacula.Exceptions.DisallowBaseException No throwing the base \Exception; throw a domain exception.
SineMacula.Exceptions.RequireEmptyCatchComment An empty catch block must comment its intentional swallow.
SineMacula.Functions.RequireSensitiveParameter Secret-named params need #[\SensitiveParameter].
SineMacula.Metrics.MaxMethodCount A class/interface/trait/enum may declare at most 20 methods (tests exempt).
SineMacula.Metrics.MethodLength A method body may have at most 50 significant lines (tests exempt).
SineMacula.Namespaces.RequireConcernsNamespace Traits must live under a Concerns namespace segment.
SineMacula.Namespaces.RequireContractsNamespace Interfaces must live under a Contracts namespace segment.
SineMacula.Namespaces.RequireEnumsNamespace Enums must live under an Enums namespace segment.
SineMacula.NamingConventions.BooleanMethodName bool methods are predicates; command verbs/@imperative exempt.
SineMacula.NamingConventions.DisallowInterfacePrefix Interface names must not use the Hungarian I prefix.
SineMacula.NamingConventions.ValidEnumCaseName Enum cases must be SCREAMING_SNAKE_CASE.
SineMacula.NamingConventions.ValidGlobalFunctionName Global functions must be declared in snake_case.
SineMacula.TypeHints.RequireConstantType Class/interface/enum/trait constants must declare a native type.
SineMacula.WhiteSpace.PromotedConstructorSpacing Blank line above each promoted-constructor parameter.

PHPStan rules

Identifier Enforces
sineMacula.mutableStaticProperty Static properties written at runtime; @managed-static opts out.

ESLint rules

All rules run in the base layer except boolean-method-name, which resolves return types and so requires the opt-in type-checked layer.

Rule Enforces
@sinemacula/no-interface-prefix Interface and type-alias names must not use the Hungarian I prefix.
@sinemacula/require-readonly-public-property Public class properties (declared or promoted) must be readonly.
@sinemacula/valid-enum-member-name Enum members must be declared in SCREAMING_SNAKE_CASE.
@sinemacula/boolean-method-name Boolean-returning methods need an is/has/can prefix; @imperative exempt.
@sinemacula/no-mutable-static No mutable exported bindings or mutable static class fields; test code exempt.
@sinemacula/max-methods-per-class A single class may declare at most 20 methods; test code exempt.
@sinemacula/no-base-error Throw a domain-specific Error subclass, never the base Error; test code exempt.
@sinemacula/require-copyright Every file must carry a documentation comment with @copyright and @author.

boolean-method-name takes additionalPrefixes, additionalPredicates and additionalCommandVerbs (string arrays) to widen the accepted vocabulary from a consumer config. max-methods-per-class takes max, no-base-error takes allow, and require-copyright takes tags to adjust their defaults.

The base layer also switches on a set of built-in rules: @typescript-eslint/no-explicit-any, max-lines-per-function (50 lines, test code exempt) and max-depth (4), plus eslint-plugin-jsdoc rules that require a documentation comment on every declared function, method and class and forbid types in @param/@returns (types belong in the signature). The type-checked layer adds @typescript-eslint/explicit-module-boundary-types and @typescript-eslint/only-throw-error.

Requirements

  • PHP ^8.3 (Composer package)
  • Node.js (npm package)

Testing

composer test           # PHPUnit suite for the custom sniffs and PHPStan rule
composer test:coverage  # suite with Clover coverage output
composer analyse        # PHPStan static analysis
composer check          # static analysis and lint via qlty
composer format         # format via qlty
composer smells         # duplication / complexity smells via qlty

Changelog

See CHANGELOG.md for a list of notable changes.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for guidelines on branching, commits, code quality, and pull requests.

Security

If you discover a security vulnerability, please report it responsibly. See SECURITY.md for the disclosure policy and contact details.

License

Licensed under the Apache License, Version 2.0.

sinemacula/coding-standards 适用场景与选型建议

sinemacula/coding-standards 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.74k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sinemacula/coding-standards 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sinemacula/coding-standards 我们能提供哪些服务?
定制开发 / 二次开发

基于 sinemacula/coding-standards 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 31
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2026-04-05