@sinemacula/coding-standards 1.3.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,7 +24,8 @@ composer require --dev sinemacula/coding-standards
|
|
|
24
24
|
npm install --save-dev @sinemacula/coding-standards
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
The npm package ships only the static configs (`js/`, `markdown/`, `yaml/`, `shell/`, `security/`). The PHP autoloaded
|
|
27
|
+
The npm package ships only the static configs (`js/`, `markdown/`, `yaml/`, `shell/`, `security/`). The PHP autoloaded
|
|
28
|
+
code lives in the Composer package.
|
|
28
29
|
|
|
29
30
|
## Usage
|
|
30
31
|
|
|
@@ -83,13 +84,15 @@ parameters:
|
|
|
83
84
|
|
|
84
85
|
#### Laravel projects
|
|
85
86
|
|
|
86
|
-
For Laravel projects, also install
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
For Laravel projects, also install
|
|
88
|
+
[`sinemacula/coding-standards-laravel`](https://github.com/sinemacula/coding-standards-laravel) and reference its
|
|
89
|
+
`SineMaculaLaravel` PHPCS standard (which includes this one) in place of `SineMacula`. It adds the
|
|
90
|
+
Laravel-specific sniffs and PHPStan rules; see that package's README for setup.
|
|
89
91
|
|
|
90
92
|
### Biome (JavaScript / TypeScript)
|
|
91
93
|
|
|
92
|
-
After installing the npm package, extend the shared Biome config from your project's `biome.json` (or
|
|
94
|
+
After installing the npm package, extend the shared Biome config from your project's `biome.json` (or
|
|
95
|
+
`.qlty/configs/biome.json` when wired through Qlty):
|
|
93
96
|
|
|
94
97
|
```json
|
|
95
98
|
{
|
|
@@ -103,7 +106,9 @@ After installing the npm package, extend the shared Biome config from your proje
|
|
|
103
106
|
}
|
|
104
107
|
```
|
|
105
108
|
|
|
106
|
-
`extends` paths are resolved through normal Node module lookup, so the package only needs to be installed (no path
|
|
109
|
+
`extends` paths are resolved through normal Node module lookup, so the package only needs to be installed (no path
|
|
110
|
+
math against `node_modules/` required). Project-specific `files.includes` and `files.excludes` stay in the consumer
|
|
111
|
+
config.
|
|
107
112
|
|
|
108
113
|
### Knip (JavaScript / TypeScript)
|
|
109
114
|
|
|
@@ -116,7 +121,8 @@ After installing the npm package, extend the shared Biome config from your proje
|
|
|
116
121
|
|
|
117
122
|
### Qlty
|
|
118
123
|
|
|
119
|
-
Reference this repository as a source in your project's `.qlty/qlty.toml`, pinning `tag` to the latest
|
|
124
|
+
Reference this repository as a source in your project's `.qlty/qlty.toml`, pinning `tag` to the latest
|
|
125
|
+
[release](https://github.com/sinemacula/coding-standards/releases):
|
|
120
126
|
|
|
121
127
|
```toml
|
|
122
128
|
[[source]]
|
|
@@ -132,22 +138,81 @@ tag = "<version>"
|
|
|
132
138
|
| `src/PhpCsFixerConfig.php` | PHP CS Fixer | Factory class for building PHP CS Fixer configurations |
|
|
133
139
|
| `php/.php-cs-fixer.rules.php` | PHP CS Fixer | Shared rules array (PSR-12 base + org conventions) |
|
|
134
140
|
| `SineMacula/ruleset.xml` | PHPCS | Auto-discovered coding standard (PSR-12 + exclusions) |
|
|
135
|
-
| `php/phpstan.neon`
|
|
141
|
+
| `php/phpstan-base.neon` | PHPStan | Base config (org-wide ignored errors + settings) |
|
|
136
142
|
| `js/biome.json` | Biome | JavaScript / TypeScript formatter + linter rules |
|
|
137
143
|
| `js/knip.json` | Knip | Unused-export detection rules |
|
|
138
144
|
| `markdown/.markdownlint.json` | markdownlint | Markdown linting rules |
|
|
139
145
|
| `yaml/.yamllint.yaml` | yamllint | YAML linting rules |
|
|
140
146
|
| `shell/.shellcheckrc` | ShellCheck | Shell script linting rules |
|
|
141
147
|
| `security/.gitleaks.toml` | Gitleaks | Secret-detection ruleset |
|
|
142
|
-
| `editorconfig/.editorconfig-checker.json` | editorconfig-checker | Disables only the max-line-length check
|
|
148
|
+
| `editorconfig/.editorconfig-checker.json` | editorconfig-checker | Disables only the max-line-length check |
|
|
149
|
+
|
|
150
|
+
## Rules
|
|
151
|
+
|
|
152
|
+
These are the custom rules this package enforces on top of PSR-12. A deliberate exception can be bypassed with the
|
|
153
|
+
native directive - `// phpcs:ignore <code>` for a sniff, `@phpstan-ignore <identifier>` for a rule.
|
|
154
|
+
|
|
155
|
+
### PHPCS sniffs
|
|
156
|
+
|
|
157
|
+
| Sniff | Enforces |
|
|
158
|
+
|-------|----------|
|
|
159
|
+
| `SineMacula.Attributes.DisallowToolingAttribute` | No IDE/tooling attributes (e.g. `JetBrains\PhpStorm`). |
|
|
160
|
+
| `SineMacula.Classes.RequireFinalClass` | Concrete classes must be `final` or `abstract` (`@inheritable` opts out). |
|
|
161
|
+
| `SineMacula.Classes.RequireReadonlyPublicProperty` | Public properties (declared or promoted) must be `readonly`. |
|
|
162
|
+
| `SineMacula.Commenting.CommentLineLength` | Standalone comment lines must not exceed 80 chars (FQCN/URL exempt). |
|
|
163
|
+
| `SineMacula.Commenting.ConsistentEnumCaseComments` | Enum case docs are all-or-nothing within an enum. |
|
|
164
|
+
| `SineMacula.Commenting.RequireConstantComment` | Every class/interface/enum/trait constant needs a doc comment. |
|
|
165
|
+
| `SineMacula.Commenting.RequireCopyrightTag` | Class/interface/enum/trait docblocks must carry an `@copyright` tag. |
|
|
166
|
+
| `SineMacula.Commenting.RequireNonPromotedParameterComment` | Plain params mixed with promoted ones need a comment. |
|
|
167
|
+
| `SineMacula.Commenting.RequirePromotedPropertyComment` | Every constructor-promoted property needs a doc comment. |
|
|
168
|
+
| `SineMacula.Exceptions.DisallowBaseException` | No throwing the base `\Exception`; throw a domain exception. |
|
|
169
|
+
| `SineMacula.Functions.RequireSensitiveParameter` | Secret-named params need `#[\SensitiveParameter]`. |
|
|
170
|
+
| `SineMacula.Metrics.MaxMethodCount` | A class/interface/trait/enum may declare at most 20 methods. |
|
|
171
|
+
| `SineMacula.Metrics.MethodLength` | A method body may have at most 50 significant lines. |
|
|
172
|
+
| `SineMacula.Namespaces.RequireConcernsNamespace` | Traits must live under a `Concerns` namespace segment. |
|
|
173
|
+
| `SineMacula.Namespaces.RequireContractsNamespace` | Interfaces must live under a `Contracts` namespace segment. |
|
|
174
|
+
| `SineMacula.Namespaces.RequireEnumsNamespace` | Enums must live under an `Enums` namespace segment. |
|
|
175
|
+
| `SineMacula.NamingConventions.BooleanMethodName` | `bool`-returning methods must read as predicates. |
|
|
176
|
+
| `SineMacula.NamingConventions.DisallowInterfacePrefix` | Interface names must not use the Hungarian `I` prefix. |
|
|
177
|
+
| `SineMacula.NamingConventions.ValidEnumCaseName` | Enum cases must be `SCREAMING_SNAKE_CASE`. |
|
|
178
|
+
| `SineMacula.NamingConventions.ValidGlobalFunctionName` | Global functions must be declared in `snake_case`. |
|
|
179
|
+
| `SineMacula.TypeHints.RequireConstantType` | Class/interface/enum/trait constants must declare a native type. |
|
|
180
|
+
|
|
181
|
+
### PHPStan rules
|
|
182
|
+
|
|
183
|
+
| Identifier | Enforces |
|
|
184
|
+
|------------|----------|
|
|
185
|
+
| `sineMacula.mutableStaticProperty` | No mutable static state; use instance state or a constant instead. |
|
|
186
|
+
|
|
187
|
+
## Requirements
|
|
188
|
+
|
|
189
|
+
- PHP ^8.3 (Composer package)
|
|
190
|
+
- Node.js (npm package)
|
|
191
|
+
|
|
192
|
+
## Testing
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
composer test # PHPUnit suite for the custom sniffs and PHPStan rule
|
|
196
|
+
composer test:coverage # suite with Clover coverage output
|
|
197
|
+
composer analyse # PHPStan static analysis
|
|
198
|
+
composer check # static analysis and lint via qlty
|
|
199
|
+
composer format # format via qlty
|
|
200
|
+
composer smells # duplication / complexity smells via qlty
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Changelog
|
|
204
|
+
|
|
205
|
+
See [CHANGELOG.md](CHANGELOG.md) for a list of notable changes.
|
|
143
206
|
|
|
144
207
|
## Contributing
|
|
145
208
|
|
|
146
|
-
Contributions are welcome
|
|
209
|
+
Contributions are welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on branching, commits, code
|
|
210
|
+
quality, and pull requests.
|
|
147
211
|
|
|
148
212
|
## Security
|
|
149
213
|
|
|
150
|
-
If you discover a security
|
|
214
|
+
If you discover a security vulnerability, please report it responsibly. See [SECURITY.md](SECURITY.md) for the
|
|
215
|
+
disclosure policy and contact details.
|
|
151
216
|
|
|
152
217
|
## License
|
|
153
218
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinemacula/coding-standards",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Centralized coding standards, static analysis configurations, and code quality tooling for all Sine Macula repositories.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Ben Carey <bdmc@sinemacula.co.uk>",
|