Skip to content

Commit e0c8bbf

Browse files
committed
Tune rulesets, update readme, autofix by default
1 parent fb7a3bb commit e0c8bbf

File tree

5 files changed

+113
-53
lines changed

5 files changed

+113
-53
lines changed

.stylelintrc

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
11
{
2+
"extends": "./vendor/space48/magento2-code-quality/rulesets/.stylelintrc",
23
"rules": {
3-
"indentation": 4,
4-
"no-descending-specificity": true,
5-
"block-opening-brace-space-before": "always",
6-
"block-opening-brace-newline-after": "always",
7-
"block-closing-brace-newline-before": "always",
8-
"selector-list-comma-newline-after": "always",
9-
"selector-pseudo-element-colon-notation": "double",
10-
"string-quotes": "single",
11-
"selector-combinator-space-after": "always",
12-
"selector-combinator-space-before": "always",
13-
"declaration-block-semicolon-newline-after": "always",
14-
"declaration-colon-space-after": "always",
15-
"declaration-colon-space-before": "never",
16-
"declaration-empty-line-before": "never",
17-
"declaration-block-trailing-semicolon":"always",
18-
"no-extra-semicolons": true,
19-
"declaration-block-semicolon-space-before": "never",
20-
"declaration-no-important": true,
21-
"comment-empty-line-before": "always",
22-
"comment-whitespace-inside": "always",
23-
"comment-no-empty": true,
24-
"selector-max-id": 0,
25-
"selector-class-pattern": "^_?[a-z0-9]+(-[a-z0-9]+)*$",
26-
"selector-type-case": "lower",
27-
"max-nesting-depth": 4,
28-
"length-zero-no-unit": true,
29-
"number-leading-zero": "never",
30-
"number-no-trailing-zeros": true,
31-
"unit-case": "lower",
32-
"color-hex-case": "lower",
33-
"color-no-invalid-hex": true,
34-
"color-hex-length": "short",
35-
"block-no-empty": true,
36-
"max-empty-lines": 1,
37-
"unit-whitelist": ["px", "rem", "%", "fr", "vw", "vh", "s", "deg"],
38-
"declaration-block-no-duplicate-properties": true,
39-
"declaration-block-no-shorthand-property-overrides": true,
40-
"shorthand-property-no-redundant-values": true,
41-
"declaration-block-no-redundant-longhand-properties": true,
42-
"no-duplicate-selectors": true,
43-
"no-empty-source": true,
44-
"selector-no-qualifying-type": true,
45-
"no-empty-first-line": true,
46-
"no-eol-whitespace": true
4+
"no-descending-specificity": null,
5+
"selector-pseudo-element-colon-notation": null,
6+
"selector-type-case": null,
7+
"max-nesting-depth": null,
8+
"number-leading-zero": null,
9+
"number-no-trailing-zeros": null,
10+
"unit-case": null,
11+
"color-hex-case": null,
12+
"color-hex-length": null,
13+
"selector-no-qualifying-type": null
4714
}
48-
}
15+
}

README.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,45 @@ based on Magento 2 coding standards but tuned to be less annoying!
66

77
## Usage
88

9-
After pulling and installing a project locally just run following command to update local git hooks
10-
and install npm packages inside Docker container:
9+
After pulling and installing/updating project locally composer hook should install linters automatically.
10+
It will add precommit git hook, so on each commit linters will run for the files added to commit.
11+
12+
If that does not happen run following command to update local git hooks and install npm packages:
1113
```shell
12-
make linters-install
14+
make linters-init
1315
```
14-
Now on pre-commit either from console or from phpstorm a linter will run against committed code
1516

16-
To run precommit manually:
17+
### Git Pre-Commit
18+
A commit will fail if linters found errors in your code, check the '_console_' tab in 'Git' section of the PhpStorm
19+
for errors output by linters. Fix all errors and commit again.
20+
21+
**Warning**
22+
By default Autofix feature is turned ON. Once you try to commit, linters will automatically fix some errors.
23+
Double check changes after.
24+
25+
When fixing errors, to see predicted linters output you can instead of trying to commit again just run manually from console:
1726
```shell
1827
make precommit
1928
```
29+
30+
### Ignoring Rules
31+
in the linters output you will see hints with rule names being violated. If for some reason you can not fix violated rule
32+
feel free to ignore it using Suppress Warning comment corresponding concrete linter type (see hints in output or google).
33+
34+
**IMPORTANT!**
35+
When ignoring a rule in the code always add a comment with the reason of why you had ignored it instead of fixing.
36+
37+
### Finetuning
38+
39+
Rules can be tuned with parameters, excluded completely or rewritten on a Project Level
40+
using the `ruleset.xml, phpmd.xml, .eslintrc, .stylelint` files in the project's root folder and committing them to project's repo.
41+
42+
If you think everyone can benefit from your rules changes - feel free to create a PR.
43+
44+
### CI Integration
45+
46+
_(TBD)_
47+
2048
To run linters as it would run on CI (from starting commit till HEAD):
2149
```shell
2250
make analyse
@@ -76,7 +104,27 @@ precommit: # analyses code staged for commit
76104
Replace the sample `a000z999` commit hash with the hash from the project where you want to start linting from.
77105
Files modified after the starting commit hash will be linted during project build and will fail the build on linter violations.
78106

79-
#### 3. Commit to project`s repo.
107+
#### 3. Add post update/install composer hooks:
108+
109+
composer.json
110+
```json
111+
{
112+
...
113+
"scripts": {
114+
"post-update-cmd": [
115+
...
116+
"make linters-init"
117+
],
118+
"post-install-cmd": [
119+
...
120+
"make linters-init"
121+
]
122+
}
123+
...
124+
}
125+
```
126+
127+
#### 4. Commit to project`s repo.
80128
Commit updated composer files, vendor folder, code-quality config files from the root and 'makefile' changes
81129

82130
### Installation on any other Magento 2 project:
@@ -104,7 +152,7 @@ eslint:
104152
```
105153
To turn off whole linter type (for example 'eslint') - remove or comment out corresponding 'task' section.
106154
107-
Linter rules can be finetuned on a project level by editing `ruleset.xml, phpmd.xml, .eslintrc` files.
155+
Linter rules can be finetuned on a project level by editing `ruleset.xml, phpmd.xml, .eslintrc, .stylelint` files.
108156
See `Space48/code-quality/rulesets/` for examples.
109157

110158
Some rules can be overwritten on a class level. See `rulesets/PhpMd/extra.xml` for examples.

grumphp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ grumphp:
2828
EXEC_GRUMPHP_COMMAND: 'warden env run --rm php-fpm'
2929
ignore_unstaged_changes: false
3030
fixer:
31-
enabled: false
31+
enabled: true
3232
fix_by_default: true
3333
tasks:
3434
phpmd:

rulesets/.stylelintrc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"rules": {
3+
"indentation": 4,
4+
"block-opening-brace-space-before": "always",
5+
"block-opening-brace-newline-after": "always",
6+
"block-closing-brace-newline-before": "always",
7+
"selector-list-comma-newline-after": "always",
8+
"string-quotes": "single",
9+
"selector-combinator-space-after": "always",
10+
"selector-combinator-space-before": "always",
11+
"declaration-block-semicolon-newline-after": "always",
12+
"declaration-colon-space-after": "always",
13+
"declaration-colon-space-before": "never",
14+
"declaration-empty-line-before": "never",
15+
"declaration-block-trailing-semicolon":"always",
16+
"no-extra-semicolons": true,
17+
"declaration-block-semicolon-space-before": "never",
18+
"declaration-no-important": true,
19+
"comment-empty-line-before": "always",
20+
"comment-whitespace-inside": "always",
21+
"comment-no-empty": true,
22+
"selector-max-id": 0,
23+
"selector-class-pattern": "^_?[a-z0-9]+(-[a-z0-9]+)*$",
24+
"length-zero-no-unit": true,
25+
"color-no-invalid-hex": true,
26+
"block-no-empty": true,
27+
"max-empty-lines": 1,
28+
"unit-whitelist": ["px", "rem", "%", "fr", "vw", "vh", "s", "deg"],
29+
"declaration-block-no-duplicate-properties": true,
30+
"declaration-block-no-shorthand-property-overrides": true,
31+
"shorthand-property-no-redundant-values": true,
32+
"declaration-block-no-redundant-longhand-properties": true,
33+
"no-duplicate-selectors": true,
34+
"no-empty-source": true,
35+
"no-empty-first-line": true,
36+
"no-eol-whitespace": true
37+
}
38+
}

rulesets/ruleset.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@
2626
<property name="absoluteComplexity" value="13" />
2727
</properties>
2828
</rule>
29+
30+
<rule ref="Generic.Files.LineLength">
31+
<properties>
32+
<property name="ignoreComments" value="true"/>
33+
</properties>
34+
</rule>
35+
2936
</ruleset>

0 commit comments

Comments
 (0)