Skip to content

Commit 91136f0

Browse files
committed
Create the bundle
0 parents  commit 91136f0

File tree

16 files changed

+652
-0
lines changed

16 files changed

+652
-0
lines changed

.gitattributes

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
ecs.php export-ignore
6+
phpstan.neon.dist export-ignore
7+
phpstan-baseline.neon
8+
phpunit.xml.dist export-ignore

.github/workflows/ci.yaml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
types: [opened, synchronize, reopened, ready_for_review]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
10+
cancel-in-progress: true
11+
12+
defaults:
13+
run:
14+
shell: bash
15+
16+
jobs:
17+
code_quality:
18+
name: Code Quality
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Install PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: 8.2
27+
tools: symfony-cli
28+
29+
- name: Install Composer dependencies
30+
run: symfony composer install --prefer-dist --no-interaction --no-progress
31+
32+
- name: Run Easy Coding Standard
33+
run: symfony php vendor/bin/ecs
34+
35+
- name: Run PHPStan
36+
run: symfony php vendor/bin/phpstan analyze
37+
38+
e2e:
39+
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
os: [ubuntu-latest, windows-latest, macos-latest]
44+
php-version: [ '8.1', '8.2', '8.3', '8.4' ]
45+
dependency-version: [ '' ]
46+
symfony-version: [ '' ]
47+
minimum-stability: [ 'stable' ]
48+
include:
49+
# dev packages (probably not needed to have multiple such jobs)
50+
- minimum-stability: 'dev'
51+
php-version: '8.4'
52+
# lowest deps
53+
- php-version: '8.1'
54+
dependency-version: 'lowest'
55+
# LTS version of Symfony
56+
- php-version: '8.1'
57+
symfony-version: '6.4.*'
58+
steps:
59+
- uses: actions/checkout@v4
60+
61+
- name: Install PHP
62+
uses: shivammathur/setup-php@v2
63+
with:
64+
php-version: 8.2
65+
tools: symfony-cli, flex
66+
67+
- name: Install Composer dependencies
68+
run: |
69+
symfony composer config minimum-stability ${{ matrix.minimum-stability }}
70+
SYMFONY_REQUIRE=${{ matrix.symfony-version || '>=6.4' }} symfony composer update ${{ matrix.dependency-version == 'lowest' && '--prefer-lowest' || '' }}
71+
72+
- name: Create a new Symfony project
73+
run: |
74+
git config --global user.email "[email protected]"
75+
git config --global user.name "Hugo Alliaume"
76+
case "${{ matrix.php-version }}" in
77+
8.1) symfony new my_app --version="6.4.*" --webapp ;;
78+
8.2) symfony new my_app --version="7.1.*" --webapp ;;
79+
8.3) symfony new my_app --version="7.2.*" --webapp ;;
80+
8.4) symfony new my_app --version="7.3.*" --webapp ;;
81+
esac
82+
83+
- name: Install kocal/oxlint-bundle
84+
working-directory: my_app
85+
run: |
86+
symfony composer config minimum-stability dev
87+
symfony composer config --json extra.symfony.allow-contrib 'true'
88+
symfony composer config repositories.oxlint-bundle '{"type":"path", "url":"../","options":{"symlink":true}}'
89+
90+
cat << EOF > config/packages/kocal_oxlint.yaml
91+
when@dev:
92+
kocal_oxlint:
93+
binary_version: '1.8.0'
94+
EOF
95+
96+
symfony composer require 'kocal/oxlint-bundle:*' --dev --no-interaction
97+
98+
cat << EOF > .oxlintrc.json
99+
{
100+
"ignorePatterns": [
101+
"assets/vendor/**",
102+
"public/assets/**",
103+
"public/bundles/**",
104+
"var/**",
105+
"vendor/**"
106+
]
107+
}
108+
EOF
109+
110+
- name: Download the Oxlint CLI
111+
working-directory: my_app
112+
run: symfony console oxlint:download
113+
114+
- name: Run Oxlint, which should fails (but it's expected!)
115+
working-directory: my_app
116+
run: bin/oxlint
117+
continue-on-error: true
118+
119+
- name: Run Oxlint --fix
120+
working-directory: my_app
121+
run: bin/oxlint check . --write --unsafe
122+
123+
- name: Run Oxlint, which should now pass
124+
working-directory: my_app
125+
run: bin/oxlint

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor/
2+
composer.lock
3+
.phpunit.result.cache
4+
5+
my_app/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 Hugo Alliaume
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# OxlintBundle
2+
3+
[![.github/workflows/ci.yaml](https://github.com/Kocal/OxlintBundle/actions/workflows/ci.yaml/badge.svg)](https://github.com/Kocal/OxlintBundle/actions/workflows/ci.yaml)
4+
[![Packagist Version](https://img.shields.io/packagist/v/kocal/oxlint-bundle)](https://packagist.org/packages/kocal/oxlint-bundle)
5+
6+
A Symfony Bundle to easily download and use [Oxlint](https://oxc.rs/docs/guide/usage/linter) (from the [Oxc project](https://oxc.rs/)) in your Symfony applications,
7+
to lint your front assets without needing Node.js (ex: when using [Symfony AssetMapper](https://symfony.com/doc/current/frontend/asset_mapper.html)).
8+
9+
> [!TIP]
10+
> If you prefer to use Biome.js instead, check [Kocal/BiomeJsBundle](https://github.com/Kocal/BiomeJsBundle)!
11+
12+
---
13+
14+
## Installation
15+
16+
Install the bundle with Composer:
17+
18+
```shell
19+
composer require kocal/oxlint-bundle --dev
20+
```
21+
22+
If you use [Symfony Flex](https://symfony.com/doc/current/setup/flex.html), everything must be configured automatically.
23+
If that's not the case, please follow the next steps:
24+
25+
<details>
26+
<summary>Manual installation steps</summary>
27+
28+
1. Register the bundle in your `config/bundles.php` file:
29+
30+
```php
31+
return [
32+
// ...
33+
Kocal\OxlintBundle\KocalOxlintBundle::class => ['dev' => true],
34+
];
35+
```
36+
37+
2. Create the configuration file `config/packages/kocal_oxlint.yaml`:
38+
39+
```yaml
40+
when@dev:
41+
kocal_oxlint:
42+
# The Biome.js CLI version to use, that you can find at https://github.com/oxc-project/oxc/tags,
43+
# it follows the pattern "oxlint_v<binary_version>"
44+
binary_version: '1.8.0'
45+
```
46+
47+
3. Create the recommended `.oxlintrc.json` file at the root of your project:
48+
49+
```json
50+
{
51+
"ignorePatterns": [
52+
"assets/vendor/**",
53+
"public/assets/**",
54+
"public/bundles/**",
55+
"var/**",
56+
"vendor/**"
57+
]
58+
}
59+
```
60+
61+
</details>
62+
63+
## Configuration
64+
65+
The bundle is configured in the `config/packages/kocal_oxlint.yaml` file:
66+
67+
```yaml
68+
when@dev:
69+
kocal_oxlint:
70+
71+
# The Biome.js CLI version to use, that you can find at https://github.com/oxc-project/oxc/tags,
72+
# it follows the pattern "oxlint_v<binary_version>"
73+
binary_version: '1.8.0'
74+
```
75+
76+
## Usage
77+
78+
### `oxlint:download`
79+
80+
Download the Oxlint binary for your configured version and for your platform (Linux, macOS, Windows).
81+
82+
By default, the command will download the binary in the `bin/` directory of your project.
83+
84+
```shell
85+
php bin/console oxlint:download
86+
bin/oxlint --version
87+
88+
# or, with a custom destination directory
89+
php bin/console oxlint:download path/to/bin
90+
path/to/bin/oxlint --version
91+
```
92+
93+
## Inspirations
94+
95+
- https://github.com/SymfonyCasts/tailwind-bundle
96+
- https://github.com/Kocal/BiomeJsBundle

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "kocal/oxlint-bundle",
3+
"description": "A Symfony Bundle to easily download and use Oxlint (from the Oxc project) in your Symfony applications, to lint your front assets without needing Node.js.",
4+
"type": "symfony-bundle",
5+
"keywords": ["oxlint", "oxc", "symfony", "bundle"],
6+
"license": "MIT",
7+
"autoload": {
8+
"psr-4": {
9+
"Kocal\\OxlintBundle\\": "src/"
10+
}
11+
},
12+
"authors": [
13+
{
14+
"name": "Hugo Alliaume",
15+
"email": "[email protected]"
16+
}
17+
],
18+
"require": {
19+
"php": ">=8.1",
20+
"symfony/console": "^6.4|^7.0",
21+
"symfony/filesystem": "^6.4|^7.0",
22+
"symfony/http-client": "^6.4|^7.0",
23+
"symfony/process": "^6.4|^7.0"
24+
},
25+
"require-dev": {
26+
"phpstan/phpstan": "^1.11",
27+
"symplify/easy-coding-standard": "^12.1.2",
28+
"symfony/framework-bundle": "^6.4|^7.0"
29+
}
30+
}

config/services.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Kocal\OxlintBundle\Command\OxlintDownloadCommand;
6+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
7+
8+
use function Symfony\Component\DependencyInjection\Loader\Configurator\abstract_arg;
9+
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
10+
11+
return static function (ContainerConfigurator $container): void {
12+
$container->services()
13+
->set('oxlint.command.download', OxlintDownloadCommand::class)
14+
->args([
15+
abstract_arg('Oxlint binary version'),
16+
service('filesystem'),
17+
])
18+
->tag('console.command');
19+
};

ecs.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Symplify\EasyCodingStandard\Config\ECSConfig;
6+
7+
return ECSConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/config',
10+
__DIR__ . '/src',
11+
])
12+
->withPreparedSets(psr12: true, strict: true)
13+
->withPhpCsFixerSets(symfony: true)
14+
;

fixtures/bootstrap.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { startStimulusApp} from '@symfony/stimulus-bundle';
2+
3+
const app=startStimulusApp();

fixtures/say-hello.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function sayHello(message : string) : void
2+
{
3+
console.log('Hello, '+message+'!');
4+
}

0 commit comments

Comments
 (0)