Skip to content

Commit a34110d

Browse files
committed
[#2069] Added docs for ESLint.
1 parent 6692223 commit a34110d

2 files changed

Lines changed: 177 additions & 19 deletions

File tree

.vortex/docs/content/tools/README.mdx

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,24 @@ build if they detect issues.
1616

1717
Head over to the tool-specific documentation to learn more.
1818

19-
| Name | Description |
20-
|------------------------------------|---------------------------------------------------------------------------------|
21-
| [Ahoy](ahoy.mdx) | CLI command wrapper |
22-
| [Behat](behat.mdx) | Testing framework for for auto-testing your business expectations |
19+
| Name | Description |
20+
|------------------------------------|-----------------------------------------------------------------------------------------|
21+
| [Ahoy](ahoy.mdx) | CLI command wrapper |
22+
| [Behat](behat.mdx) | Testing framework for for auto-testing your business expectations |
2323
| [DCLint](dclint.mdx) | A command-line tool for validating and enforcing best practices in Docker Compose files |
24-
| [Docker](docker.mdx) | A platform for containerizing and running applications |
25-
| [Doctor](doctor.mdx) | Check **Vortex** project requirements or retrieve environment information |
26-
| [Drush](drush.mdx) | Command line shell and Unix scripting interface for Drupal |
27-
| [Gherkin Lint](gherkin-lint.mdx) | Provides a Gherkin linter for PHP |
28-
| [Git artifact](git-artifact.mdx) | Package and push files to remote repositories |
29-
| [Hadolint](hadolint.mdx) | A smarter Dockerfile linter that helps you build best practice container images |
30-
| [PHPCS](phpcs.mdx) | Check that code adheres to coding standards |
31-
| [PHPMD](phpmd.mdx) | Detect code smells and possible errors |
32-
| [PHPStan](phpstan.mdx) | PHP Static Analysis Tool |
33-
| [PHPUnit](phpunit.mdx) | The PHP Testing Framework |
34-
| [Pygmy](pygmy.mdx) | A local reverse-proxy and email catcher |
35-
| [Rector](rector.mdx) | Instant Upgrades and Automated Refactoring |
36-
| [Renovate](renovate.mdx) | A bot for automated dependency updates |
37-
| [Twig CS Fixer](twig-cs-fixer.mdx) | Checkstyle for Twig |
38-
| [Xdebug](xdebug.mdx) | Debugger and Profiler Tool for PHP |
24+
| [Docker](docker.mdx) | A platform for containerizing and running applications |
25+
| [Doctor](doctor.mdx) | Check **Vortex** project requirements or retrieve environment information |
26+
| [Drush](drush.mdx) | Command line shell and Unix scripting interface for Drupal |
27+
| [ESLint](eslint.mdx) | JavaScript linter with Prettier integration for custom modules |
28+
| [Gherkin Lint](gherkin-lint.mdx) | Provides a Gherkin linter for PHP |
29+
| [Git artifact](git-artifact.mdx) | Package and push files to remote repositories |
30+
| [Hadolint](hadolint.mdx) | A smarter Dockerfile linter that helps you build best practice container images |
31+
| [PHPCS](phpcs.mdx) | Check that code adheres to coding standards |
32+
| [PHPMD](phpmd.mdx) | Detect code smells and possible errors |
33+
| [PHPStan](phpstan.mdx) | PHP Static Analysis Tool |
34+
| [PHPUnit](phpunit.mdx) | The PHP Testing Framework |
35+
| [Pygmy](pygmy.mdx) | A local reverse-proxy and email catcher |
36+
| [Rector](rector.mdx) | Instant Upgrades and Automated Refactoring |
37+
| [Renovate](renovate.mdx) | A bot for automated dependency updates |
38+
| [Twig CS Fixer](twig-cs-fixer.mdx) | Checkstyle for Twig |
39+
| [Xdebug](xdebug.mdx) | Debugger and Profiler Tool for PHP |
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
---
2+
sidebar_label: ESLint
3+
---
4+
5+
# ESLint - JavaScript Linter
6+
7+
- https://eslint.org/
8+
- https://github.com/eslint/eslint
9+
10+
> ESLint is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code, with the goal of making code more consistent and avoiding bugs.
11+
12+
**Vortex** comes with [pre-configured ESLint ruleset](https://github.com/drevops/vortex/blob/develop/.eslintrc.json) for Drupal projects, along with [Prettier](https://prettier.io/) integration for automatic code formatting.
13+
14+
:::info
15+
ESLint in Vortex is configured to lint **custom modules only** (`web/modules/custom`). Custom themes should maintain their own ESLint configuration within the theme directory.
16+
:::
17+
18+
## Usage
19+
20+
### Check for violations
21+
22+
import Tabs from '@theme/Tabs';
23+
import TabItem from '@theme/TabItem';
24+
25+
<Tabs>
26+
<TabItem value="ahoy" label="Ahoy" default>
27+
```shell
28+
ahoy lint-fe
29+
```
30+
</TabItem>
31+
<TabItem value="docker-compose" label="Docker Compose">
32+
```shell
33+
docker compose exec cli yarn run lint-js
34+
```
35+
</TabItem>
36+
</Tabs>
37+
38+
### Fix violations
39+
40+
ESLint supports automatic fixing of many violations using the `--fix` flag. Prettier integration provides additional auto-formatting capabilities.
41+
42+
<Tabs>
43+
<TabItem value="ahoy" label="Ahoy" default>
44+
```shell
45+
ahoy lint-fe-fix
46+
```
47+
</TabItem>
48+
<TabItem value="docker-compose" label="Docker Compose">
49+
```shell
50+
docker compose exec cli yarn run lint-fix-js
51+
```
52+
</TabItem>
53+
</Tabs>
54+
55+
## Configuration
56+
57+
See [configuration reference](https://eslint.org/docs/latest/use/configure/).
58+
59+
All global configuration takes place in the [`.eslintrc.json`](https://github.com/drevops/vortex/blob/develop/.eslintrc.json) file.
60+
61+
By default, ESLint will check against the following rules:
62+
63+
- `airbnb-base` - Airbnb's base JavaScript style guide
64+
- `plugin:prettier/recommended` - Prettier integration for code formatting
65+
- `plugin:yml/recommended` - YAML file linting
66+
67+
The configuration includes Drupal-specific globals:
68+
69+
- `Drupal`, `drupalSettings`, `drupalTranslations`
70+
- `jQuery`, `once`
71+
- `CKEditor5`
72+
- And other common Drupal frontend libraries
73+
74+
Targets include custom modules only:
75+
76+
```json
77+
{
78+
"scripts": {
79+
"lint-js": "eslint web/modules/custom --ext .js"
80+
}
81+
}
82+
```
83+
84+
Adding or removing targets in `package.json`:
85+
86+
```json
87+
{
88+
"scripts": {
89+
"lint-js": "eslint web/modules/custom web/sites/default --ext .js"
90+
}
91+
}
92+
```
93+
94+
### Prettier Integration
95+
96+
Prettier is integrated via `eslint-plugin-prettier` and provides automatic code formatting. The rule `"prettier/prettier": "error"` ensures that all code formatting issues are caught by ESLint.
97+
98+
When you run `ahoy lint-fe-fix`, both ESLint's `--fix` and Prettier's formatting are applied automatically.
99+
100+
## Ignoring
101+
102+
### Global Ignoring
103+
104+
Ignoring paths **globally** takes place in the [`.eslintignore`](https://github.com/drevops/vortex/blob/develop/.eslintignore) file:
105+
106+
```text
107+
node_modules/
108+
vendor/
109+
web/core/
110+
web/libraries/
111+
web/modules/contrib/
112+
web/themes/contrib/
113+
*.min.js
114+
```
115+
116+
### Inline Ignoring
117+
118+
To ignore **all ESLint rules** within a file, place in the file header:
119+
120+
```javascript
121+
/* eslint-disable */
122+
```
123+
124+
To ignore **a specific rule** within a file, place in the file header:
125+
126+
```javascript
127+
/* eslint-disable no-console, no-unused-vars */
128+
```
129+
130+
To ignore rules for a **code block**:
131+
132+
```javascript
133+
/* eslint-disable no-console */
134+
console.log('Debug information');
135+
/* eslint-enable no-console */
136+
```
137+
138+
To ignore only the **next line**:
139+
140+
```javascript
141+
// eslint-disable-next-line no-console
142+
console.log('Single debug statement');
143+
```
144+
145+
To ignore rules for the **current line** (inline):
146+
147+
```javascript
148+
console.log('Debug'); // eslint-disable-line no-console
149+
```
150+
151+
## Ignoring fail in continuous integration pipeline
152+
153+
This tool runs in continuous integration pipeline by default and fails the build
154+
if there are any violations.
155+
156+
Set `VORTEX_CI_NODEJS_LINT_IGNORE_FAILURE` environment variable to `1` to ignore
157+
failures. The tool will still run and report violations, if any.

0 commit comments

Comments
 (0)