Skip to content

Commit ddb0036

Browse files
committed
minor #18 Setup ESLint, and lint/format files (Kocal)
This PR was squashed before being merged into the main branch. Discussion ---------- Setup ESLint, and lint/format files | Q | A | ------------- | --- | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Tickets | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Hi 👋 We are already using Prettier for the formatting and that's really nice, but using a linter is a must have, especially if it's an open-source project where many people can contribute. I've configured ESLint (and Prettier) in the root `package.json`, because I saw that Jest were configured in workspaces's `package.json` files, but I can move it in external files if needed. The ESLint configuration is pretty basic, we extends the recommended configuration and use the [Jest ESLint plugin](https://github.com/jest-community/eslint-plugin-jest#readme). This PR add 4 new Yarn commands: - `lint`, run ESLint and fix linting issues - `format`, run Prettier on `.js`, `.json` and `.md` files, and fix formatting issues - `check-lint` (for the CI), check if ESLint was run - `check-format` (for the CI), check if Prettier was run Each workspaces have a new Yarn command `lint` that will run ESLint locally to the workspace, this way `@babel/eslint-parser` will find the Babel config file used by the workspace, and it won't fail if ESLint was ran in the repository root. WDYT? Thanks! Commits ------- 3716e1c Setup ESLint, and lint/format files
2 parents ee799c7 + 3716e1c commit ddb0036

File tree

17 files changed

+112
-46
lines changed

17 files changed

+112
-46
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ jobs:
2020
runs-on: ubuntu-latest
2121
steps:
2222
- uses: actions/checkout@master
23-
- name: Prettier
24-
run: |
25-
yarn global add prettier@^2.2.0
26-
~/.yarn/bin/prettier --check src/*/Resources/assets/{src,test}/*.js --config .prettierrc.json
23+
- run: yarn
24+
- run: yarn check-lint
25+
- run: yarn check-format
2726

2827
tests-php-low-deps:
2928
runs-on: ubuntu-latest

.prettierrc.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ infrastructure.
1818
This problem is not new: it looks a whole lot like the state of Symfony in PHP
1919
before Symfony Flex. We need a Symfony Flex equivalent for JavaScript: a tool to
2020
build amazing User Experiences as quickly as we can now setup
21-
[an HTTP client](https://symfony.com/doc/current/http_client.html),
22-
[a Mailer](https://symfony.com/doc/current/mailer.html) or
21+
[an HTTP client](https://symfony.com/doc/current/http_client.html),
22+
[a Mailer](https://symfony.com/doc/current/mailer.html) or
2323
[an administration panel](https://symfony.com/doc/current/bundles/EasyAdminBundle/index.html).
2424

2525
**That's Symfony UX.**
@@ -28,24 +28,24 @@ build amazing User Experiences as quickly as we can now setup
2828

2929
# Packages
3030

31-
* [UX Chart.js](https://github.com/symfony/ux-chartjs):
32-
[Chart.js](https://www.chartjs.org/) chart library integration for Symfony
33-
* [UX Cropper.js](https://github.com/symfony/ux-cropperjs):
34-
[Cropper.js](https://fengyuanchen.github.io/cropperjs/) image cropper library integration for Symfony
35-
* [UX Dropzone](https://github.com/symfony/ux-dropzone):
36-
File input drag-and-drop zones for Symfony Forms
37-
* [UX LazyImage](https://github.com/symfony/ux-lazy-image):
38-
Improve image loading performances through lazy-loading and data-uri thumbnails
39-
* [UX Swup](https://github.com/symfony/ux-swup):
40-
[Swup](https://swup.js.org/) page transition library integration for Symfony
31+
- [UX Chart.js](https://github.com/symfony/ux-chartjs):
32+
[Chart.js](https://www.chartjs.org/) chart library integration for Symfony
33+
- [UX Cropper.js](https://github.com/symfony/ux-cropperjs):
34+
[Cropper.js](https://fengyuanchen.github.io/cropperjs/) image cropper library integration for Symfony
35+
- [UX Dropzone](https://github.com/symfony/ux-dropzone):
36+
File input drag-and-drop zones for Symfony Forms
37+
- [UX LazyImage](https://github.com/symfony/ux-lazy-image):
38+
Improve image loading performances through lazy-loading and data-uri thumbnails
39+
- [UX Swup](https://github.com/symfony/ux-swup):
40+
[Swup](https://swup.js.org/) page transition library integration for Symfony
4141

4242
# Let's build an amazing ecosystem together
4343

4444
Symfony UX is an **initiative**: its aim is to build an ecosystem. To achieve this,
45-
we need your help: what other packages could we create in Symfony UX? What about a
46-
library that automatically adds an [input mask](https://imask.js.org/) to the text
45+
we need your help: what other packages could we create in Symfony UX? What about a
46+
library that automatically adds an [input mask](https://imask.js.org/) to the text
4747
fields of your Symfony forms? Or the ability to make the `EntityType` render with
48-
[AJAX auto-completion](https://tarekraafat.github.io/autoComplete.js)? Anything you
48+
[AJAX auto-completion](https://tarekraafat.github.io/autoComplete.js)? Anything you
4949
do in JavaScript could be done streamlined as a UX package.
5050

5151
We have some ideas and we will release more packages in the coming days. The rest

package.json

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,49 @@
11
{
22
"private": true,
3-
"workspaces": ["src/*/Resources/assets"],
3+
"workspaces": [
4+
"src/*/Resources/assets"
5+
],
46
"scripts": {
57
"build": "yarn workspaces run build",
6-
"test": "yarn workspaces run test"
8+
"test": "yarn workspaces run test",
9+
"lint": "yarn workspaces run lint --fix",
10+
"format": "prettier src/*/Resources/assets/{src,test}/*.js {,src/*/}*.{json,md} --write",
11+
"check-lint": "yarn lint --no-fix",
12+
"check-format": "yarn format --no-write --check"
13+
},
14+
"devDependencies": {
15+
"@babel/eslint-parser": "^7.12.1",
16+
"eslint": "^7.15.0",
17+
"eslint-config-prettier": "^6.15.0",
18+
"eslint-plugin-jest": "^24.1.3",
19+
"prettier": "^2.2.1"
20+
},
21+
"eslintConfig": {
22+
"root": true,
23+
"parser": "@babel/eslint-parser",
24+
"extends": [
25+
"eslint:recommended",
26+
"prettier"
27+
],
28+
"env": {
29+
"browser": true
30+
},
31+
"overrides": [
32+
{
33+
"files": [
34+
"src/*/Resources/assets/test/*.js"
35+
],
36+
"extends": [
37+
"plugin:jest/recommended"
38+
]
39+
}
40+
]
41+
},
42+
"prettier": {
43+
"printWidth": 120,
44+
"trailingComma": "es5",
45+
"tabWidth": 4,
46+
"jsxBracketSameLine": true,
47+
"singleQuote": true
748
}
849
}

src/Chartjs/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ export default class extends Controller {
9292
console.log(event.detail.chart); // You can access the chart instance using the event details
9393

9494
// For instance you can listen to additional events
95-
event.detail.chart.options.onHover = (mouseEvent) => { /* ... */ };
96-
event.detail.chart.options.onClick = (mouseEvent) => { /* ... */ };
95+
event.detail.chart.options.onHover = (mouseEvent) => {
96+
/* ... */
97+
};
98+
event.detail.chart.options.onClick = (mouseEvent) => {
99+
/* ... */
100+
};
97101
}
98102
}
99103
```

src/Chartjs/Resources/assets/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
},
1515
"scripts": {
1616
"build": "babel src -d dist",
17-
"test": "babel src -d dist && jest"
17+
"test": "babel src -d dist && jest",
18+
"lint": "eslint src test"
1819
},
1920
"dependencies": {
2021
"chart.js": "^2.9.4"

src/Chartjs/composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"name": "symfony/ux-chartjs",
33
"type": "symfony-bundle",
44
"description": "Chart.js integration for Symfony",
5-
"keywords": ["symfony", "ux", "chart", "chart.js", "chartjs"],
5+
"keywords": [
6+
"symfony",
7+
"ux",
8+
"chart",
9+
"chart.js",
10+
"chartjs"
11+
],
612
"homepage": "https://symfony.com",
713
"license": "MIT",
814
"authors": [

src/Cropperjs/Resources/assets/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
},
1919
"scripts": {
2020
"build": "babel src -d dist",
21-
"test": "babel src -d dist && jest"
21+
"test": "babel src -d dist && jest",
22+
"lint": "eslint src test"
2223
},
2324
"dependencies": {
2425
"cropperjs": "^1.5.9"

src/Cropperjs/composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
"name": "symfony/ux-cropperjs",
33
"type": "symfony-bundle",
44
"description": "Cropper.js integration for Symfony",
5-
"keywords": ["symfony", "ux", "cropper", "cropper.js", "cropperjs"],
5+
"keywords": [
6+
"symfony",
7+
"ux",
8+
"cropper",
9+
"cropper.js",
10+
"cropperjs"
11+
],
612
"homepage": "https://symfony.com",
713
"license": "MIT",
814
"authors": [

src/Dropzone/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ the `@symfony/ux-dropzone/src/style.css` autoimport to `false`:
6969
}
7070
```
7171

72-
> *Note*: you should put the value to `false` and not remove the line so that Symfony Flex
72+
> _Note_: you should put the value to `false` and not remove the line so that Symfony Flex
7373
> won't try to add the line again in the future.
7474
7575
Once done, the default stylesheet won't be used anymore and you can implement your own CSS on

0 commit comments

Comments
 (0)