Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

feat(twig-linter): Configuration (twigcs + grumphp) and fixes on the templates - TWIG-51 #162

Merged
merged 6 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
build
dist
node_modules
vendor
yarn-error.log
.idea
composer.lock
26 changes: 26 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "ec-europa/ecl-twig",
"description": "Twig components for the EC new visual identity.",
"license": "EUPL-1.1",
"keywords": [
"ecl",
"twig",
"components",
"european commission",
"storybook"
],
"scripts": {
"twig-cs": "./vendor/bin/twigcs ./src/*/packages",
"cs": "./vendor/bin/twigcs",
"twig-lint": "./vendor/bin/twig-lint lint ./src/*/packages",
"lint": "./vendor/bin/twig-lint lint",
"grump-cs" : "php ./vendor/bin/grumphp run",
"grump-en": "php ./vendor/bin/grumphp git:init",
"grump-dis": "php ./vendor/bin/grumphp git:deinit"
},
"require-dev": {
"friendsoftwig/twigcs": "^3.1.3",
"asm89/twig-lint": "^1.0.2",
"phpro/grumphp": "^0.16.1"
}
}
55 changes: 54 additions & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,65 @@ yarn start:eu

## Lint

Check coding conventions (JS only):
This library is an implementation of the ECL vanilla components using the twig render engine. Being these twig templates used primarily used in a Drupal environment the version of twig language to be used is the [1.x](https://twig.symfony.com/doc/1.x/).

Please ensure that no syntax or features from twig 2.x is used, in order to help you with the checks on the syntax and formatting of the twig templates different solution for sniffig and linting the files are available.

### Js

```bash
yarn lint
```

### Twig

The libraries we use for sniffing and linting the twig templates all are php ones, therefore in order to be able to use the functionality in ECl-twig you would need a working installation of php (7.x) and composer to be installed.

```bash
composer install
```
One you have the libraries installed your system should be already configured for automatically running the sniffer in a pre-commit hook.
You can also run the sniffer manually on the code in different ways using the command line:

```bash
composer run twig-cs
```
Executes the [twigcs](https://github.com/friendsoftwig/twigcs) on all the packages.

```bash
composer run cs "pathToTheTemplateFile"
```
Executes the [twigcs](https://github.com/friendsoftwig/twigcs) script on the coponent you specified.
planctus marked this conversation as resolved.
Show resolved Hide resolved

```bash
composer run twig-lint
```
Runs the [twig-lint](https://github.com/asm89/twig-lint) sniff against all the packages.

```bash
composer run lint "pathToTheFolder"
```
Runs the [twig-lint](https://github.com/asm89/twig-lint) sniff against the folder you specified.

```bash
composer run grump-cs
```
Runs [grumphp](https://github.com/phpro/grumphp) on all the packages, one of its tasks is twigcs, the output of this command should be equal to "composer run twig-cs".

#### Disable/Enable pre-commit hook

Your environment should be already configured once composer install has run, but you can enable and disable the automatic check happening in the pre-commit hook by running these commands:

```bash
composer run grump-en
```
To enable the pre-commit hook.

```bash
composer run grump-dis
```
To disable the pre-commit hook.

## Test

Check snpashots with:
Expand Down
17 changes: 17 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parameters:
bin_dir: "./vendor/bin"
git_dir: "."
process_timeout: 300
tasks:
twigcs:
ruleset: 'Allocine\Twigcs\Ruleset\Official'
composer:
no_check_lock: true
yamllint:
parse_custom_tags: true
git_blacklist:
keywords:
- "die("
- "var_dump("
- "exit;"
- "console.log("