Skip to content

Commit f4eb8f0

Browse files
Added Biome linter
1 parent 3b9885b commit f4eb8f0

10 files changed

Lines changed: 408 additions & 6 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea/
22
vendor/
3+
node_modules/
34

45
pint.json
56

@@ -9,3 +10,4 @@ pint.json
910
*.orig
1011

1112
composer.lock
13+
package-lock.json

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,25 @@ It is also possible to establish dependence in the global area of visibility:
3030
composer global require dragon-code/codestyler
3131
```
3232

33+
If you need to apply code-style to JS, TS, CSS, JSON, and other files, you also need to install an additional dependency
34+
in your project:
35+
36+
```bash
37+
npm i -D @biomejs/biome
38+
```
39+
40+
Next, write the commands in the `package.json` file:
41+
42+
```json
43+
{
44+
"scripts": {
45+
"lint": "npx @biomejs/biome lint --write",
46+
"format": "npx @biomejs/biome format --write",
47+
"style": "npm run lint && npm run format"
48+
}
49+
}
50+
```
51+
3352
After installing the dependency, add a file copy command to the `scripts.post-update-cmd` section.
3453
This will automatically copy the `pint.json` file to the project root.
3554

@@ -44,6 +63,7 @@ You can also add copying the `.editorconfig` file to help the IDE and calling no
4463
"post-update-cmd": [
4564
"vendor/bin/codestyle pint 8.4",
4665
"vendor/bin/codestyle editorconfig",
66+
"vendor/bin/codestyle npm",
4767
"composer normalize"
4868
]
4969
}
@@ -58,6 +78,7 @@ When using a globally established dependence, the call call must be replaced wit
5878
"post-update-cmd": [
5979
"codestyle pint 8.4",
6080
"codestyle editorconfig",
81+
"codestyle npm",
6182
"composer normalize"
6283
]
6384
}
@@ -74,7 +95,11 @@ found [here](https://laravel.com/docs/pint).
7495
The linter is invoked by a console command:
7596

7697
```bash
98+
# For PHP
7799
composer style
100+
101+
# For JS, TS, CSS, JSON, etc.
102+
npm run style
78103
```
79104

80105
### EditorConfig
@@ -125,6 +150,24 @@ Now you can just a run console command:
125150
composer update
126151
```
127152

153+
### Npm Linter
154+
155+
[Biome](https://biomejs.dev) - format, lint, and more in a fraction of a second.
156+
157+
To do this, make sure the `biome.json` file is in the root of the project.
158+
You can also automate this process by adding a call to the file copy function in the `scripts.post-update-cmd`
159+
section of the `composer.json` file.
160+
161+
```JSON
162+
{
163+
"scripts": {
164+
"post-update-cmd": [
165+
"vendor/bin/codestyle npm"
166+
]
167+
}
168+
}
169+
```
170+
128171
### Finalized `composer.json`
129172

130173
After completing all the steps, the `composer.json` file will have the following changes:
@@ -143,12 +186,29 @@ After completing all the steps, the `composer.json` file will have the following
143186
"post-update-cmd": [
144187
"vendor/bin/codestyle pint 8.4",
145188
"vendor/bin/codestyle editorconfig",
189+
"vendor/bin/codestyle npm",
146190
"composer normalize"
147191
],
148192
"style": "vendor/bin/pint --parallel"
149193
}
150194
}
195+
```
196+
197+
### Finalized `package.json`
198+
199+
After completing all the steps, the `package.json` file will have the following changes:
151200

201+
```json
202+
{
203+
"scripts": {
204+
"lint": "npx @biomejs/biome lint --write",
205+
"format": "npx @biomejs/biome format --write",
206+
"style": "npm run lint && npm run format"
207+
},
208+
"devDependencies": {
209+
"@biomejs/biome": "^2.2.2"
210+
}
211+
}
152212
```
153213

154214
### IDE

bin/codestyle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
declare(strict_types=1);
55

66
use DragonCode\Codestyler\Console\EditorConfigCommand;
7+
use DragonCode\Codestyler\Console\NpmCommand;
78
use DragonCode\Codestyler\Console\PintCommand;
89
use Symfony\Component\Console\Application;
910

1011
if (PHP_SAPI !== 'cli' || (PHP_MAJOR_VERSION < 8 && PHP_MINOR_VERSION < 2)) {
1112
echo 'Warning: should be invoked via the CLI minimum version of PHP 8.2, not the '
12-
. PHP_SAPI . ' '
13-
. PHP_MAJOR_VERSION . '.'
14-
. PHP_MINOR_VERSION;
13+
. PHP_SAPI . ' '
14+
. PHP_MAJOR_VERSION . '.'
15+
. PHP_MINOR_VERSION;
1516

1617
exit(1);
1718
}
@@ -41,7 +42,8 @@ require_once $file;
4142

4243
$application = new Application('The Dragon Code: Styler', '6.x');
4344

44-
$application->add(new EditorConfigCommand());
45-
$application->add(new PintCommand());
45+
$application->add(new EditorConfigCommand);
46+
$application->add(new PintCommand);
47+
$application->add(new NpmCommand);
4648

4749
$application->run();

biome.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": false
7+
},
8+
"files": {
9+
"ignoreUnknown": false,
10+
"includes": [
11+
"**",
12+
"!node_modules",
13+
"!vendor",
14+
"!composer.lock",
15+
"!package-lock.json"
16+
]
17+
},
18+
"formatter": {
19+
"enabled": true,
20+
"indentStyle": "space",
21+
"indentWidth": 4
22+
},
23+
"linter": {
24+
"enabled": true,
25+
"rules": {
26+
"recommended": true
27+
}
28+
},
29+
"javascript": {
30+
"formatter": {
31+
"quoteStyle": "double"
32+
}
33+
},
34+
"json": {
35+
"formatter": {
36+
"enabled": true,
37+
"bracketSpacing": true,
38+
"expand": "always"
39+
},
40+
"parser": {
41+
"allowComments": true
42+
}
43+
},
44+
"assist": {
45+
"enabled": true,
46+
"actions": {
47+
"source": {
48+
"organizeImports": "on"
49+
}
50+
}
51+
}
52+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@
7373
"php bin/codestyle pint 8.2",
7474
"composer normalize"
7575
],
76-
"style": "vendor/bin/pint"
76+
"style": "vendor/bin/pint --parallel ./bin/codestyle ./src/ ./tests"
7777
}
7878
}

package-lock.json

Lines changed: 177 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)