Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV-37: Use eslint to lint custom javascript #146

Merged
merged 24 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
cb63310
Add scaffolding for eslint to the skeleton
jesconstantine Jun 7, 2023
871ac81
Use node v18 in nvmrc
jesconstantine Jun 7, 2023
b22f08b
Update docs with node version, npm context
jesconstantine Jun 7, 2023
da5009c
Update circle to use node v 18
jesconstantine Jun 7, 2023
ee72af2
TEMPORARY: pin the-build to our dev branch version for eslint
jesconstantine Jun 7, 2023
fa889dd
Remove illegal character from package.json name
jesconstantine Jun 7, 2023
a4f1310
Add node package to check dependencies, used in phing target
jesconstantine Jun 7, 2023
4bb74e7
Update readme
jesconstantine Jun 7, 2023
797638f
Add npx and phing commands to ddev
jesconstantine Jun 7, 2023
7fa63f0
Fix readme formatting for easier "quick setup" ordered list coding
jesconstantine Jun 7, 2023
ced6bd7
Remove unneeded new setup step
jesconstantine Jun 7, 2023
8914717
Format alltheorderedlists with 1.
jesconstantine Jun 7, 2023
33f184e
Remove project-level dependencies
jesconstantine Jun 26, 2023
98f18f0
Revert "Remove project-level dependencies"
jesconstantine Jun 26, 2023
8be8573
Remove unneeded package dependencies
jesconstantine Jul 13, 2023
ffc899f
Remove legacy ddev web container command for npx
jesconstantine Jul 13, 2023
b14ca24
Remove reference to npm as a dependency since it's in ddev already
jesconstantine Jul 13, 2023
e7a2d23
Add link to package.json name convention requirements
jesconstantine Jul 13, 2023
2cb502b
Try removing eslint yaml plugin from project root package.json
jesconstantine Jul 13, 2023
ca06fcb
Reference eslint configuration in the-build
jesconstantine Jul 13, 2023
893b054
Remove node as a project dependency - it ships on ddev.
jesconstantine Jul 13, 2023
24d75fd
Use php 8.1.18
agentrickard Aug 16, 2023
74b3e6e
Merge remote-tracking branch 'origin/develop' into dev-37-eslint
byrond Aug 16, 2023
19885d8
Revert "Use php 8.1.18"
agentrickard Aug 16, 2023
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
environment:
- PALANTIR_ENVIRONMENT: circleci
- DRUPAL_ROOT: web
- NODE_VERSION: 8
- NODE_VERSION: 18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #144 - thanks Byron!


steps:
- run:
Expand Down
7 changes: 7 additions & 0 deletions .ddev/commands/web/npx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

## Description: Run npx which executes node binaries.
## Usage: npx [node binary] [options]
## Example: "npx eslint --ext .js docroot/modules/custom"

node_modules/.bin/npx "$@"
jesconstantine marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions .ddev/commands/web/phing
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

## Description: Run phing inside the shell with `ddev phing`

vendor/bin/phing "$@"
Comment on lines +1 to +5
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows us to run ddev phing ...

1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Add directories and files to ignore: https://eslint.org/docs/latest/use/configure/ignore#the-eslintignore-file
5 changes: 5 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"drupal"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We just use Drupal Core's rules and config for eslint.

]
}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
18
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From #144 - thanks Byron!

102 changes: 57 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ The development dependencies are:
* [DDev Local](https://ddev.com/ddev-local/)
* ddev can be installed with [homebrew](https://brew.sh/): `brew install ddev`

The dependencies for linting custom javascript are:

* [Node](https://nodejs.org/en/) version 18.x.x or greater.
* [npm](https://www.npmjs.com/get-npm) version 9.x.x or greater.
jesconstantine marked this conversation as resolved.
Show resolved Hide resolved

Once you have your dependencies installed, setting up this skeleton will take at least another hour, depending on your internet connection.

Some of the commands below will prompt you for a response, with the default answer in brackets. For this quick start, hit return to accept each default answer:
Expand All @@ -33,36 +38,38 @@ Enter a short name for your project [example] :

1. Create a new project called "example" based on this template:

```
composer create-project palantirnet/drupal-skeleton example dev-develop --no-interaction
```

This skeleton is based on Drupal 10. If you would like to install and use Drupal 9 instead, run:
```
composer create-project palantirnet/drupal-skeleton example dev-drupal9 --no-interaction
```

2. Go into your new project directory and update the ddev configuration in `.ddev/config.yml`:
```
composer create-project palantirnet/drupal-skeleton example dev-develop --no-interaction
```

This skeleton is based on Drupal 10. If you would like to install and use Drupal 9 instead, run:
Comment on lines -36 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes are all just formatting to allow us to just use 1.


```
# Update to match your project name. Using "drupal-skeleton" would make the site
# accessible at 'drupal-skeleton.ddev.site'.
name: drupal-skeleton
```
composer create-project palantirnet/drupal-skeleton example dev-drupal9 --no-interaction
```

1. Go into your new project directory and update the ddev configuration in `.ddev/config.yml`:

# Use 'docroot' for Acquia, or 'web' for Pantheon or Platform.sh.
docroot: web
```
```
# Update to match your project name. Using "drupal-skeleton" would make the site
# accessible at 'drupal-skeleton.ddev.site'.
name: drupal-skeleton

3. From inside the ddev environment, run the script from `palantirnet/the-build` to set up the default Drupal variables and install Drupal:
# Use 'docroot' for Acquia, or 'web' for Pantheon or Platform.sh.
docroot: web
```

1. From inside the ddev environment, run the script from `palantirnet/the-build` to set up the default Drupal variables and install Drupal:

```
ddev start
ddev ssh
vendor/bin/the-build-installer
```
```
ddev start
ddev ssh
vendor/bin/the-build-installer
```

1. In your web browser, visit [http://example.ddev.site](http://example.ddev.site)

5. In your web browser, visit [http://example.ddev.site](http://example.ddev.site)
6. _Optional:_ While you are logged into the ddev environment, you can run Drush commands like `drush status`.
1. _Optional:_ While you are logged into the ddev environment, you can run Drush commands like `drush status`.

### Extra Credit

Expand Down Expand Up @@ -122,6 +129,11 @@ Update the `composer.json`:
composer update --lock
```

Update the `package.json`:

* Change the `name` from `palantirnet--drupal-skeleton` to `palantirnet--PROJECTNAME`
* Update the `description` with a brief description of your project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new addition.

### Configure your ddev development environment

Go into your new project directory and update the ddev configuration in `.ddev/config.yml`.
Expand Down Expand Up @@ -169,17 +181,17 @@ git push -u origin develop
If you're allergic to phing and Benadryl isn't helping, you can also remove the-build:

1. `composer remove --dev palantirnet/the-build`
2. `rm -r .the-build`
3. `rm build.xml`
4. This will remove drush, coder, and phpmd -- if you want those dependencies, you'll need to add them back to your project:
1.`rm -r .the-build`
1. `rm build.xml`
1. This will remove drush, coder, and phpmd -- if you want those dependencies, you'll need to add them back to your project:

```
composer require --dev drush/drush drupal/coder phpmd/phpmd
```

5. Review your `web/sites/default/settings.*.php` files (the-build managed these for you)
6. Install your build tooling of choice... or nothing at all...
7. _Update your project's README_
1. Review your `web/sites/default/settings.*.php` files (the-build managed these for you)
1. Install your build tooling of choice... or nothing at all...
1. _Update your project's README_

See also: [Documentation on using the-build](https://github.com/palantirnet/the-build#using-the-build)

Expand Down Expand Up @@ -214,24 +226,24 @@ In Drupal 8 development, all (or most) Drupal configuration should be exported a
* Set the admin email address (your development environment will trap all emails)
* Turn the Cron interval down to "never"
* Uninstall unnecessary modules (e.g. Search, History, Comment)
2. Export your config:
1. Export your config:

```
drush cex -y
```
```
drush cex -y
```

3. You should have a ton of new `*.yml` files in `config/sites/default/`. Add them, and this config change, to git:
1. You should have a ton of new `*.yml` files in `config/sites/default/`. Add them, and this config change, to git:

```
git add config/
git ci -m "Initial Drupal configuration."
git push
```
5. Reinstall your site and verify that your config is ready to go:
```
git add config/
git ci -m "Initial Drupal configuration."
git push
```
1. Reinstall your site and verify that your config is ready to go:

```
vendor/bin/phing install
```
```
vendor/bin/phing install
```

## More information

Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "git",
"url": "https://github.com/palantirnet/the-build"
Comment on lines +16 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary. After this PR is approved we should be able to remove.

}
],
"require": {
Expand All @@ -32,7 +36,7 @@
"dmore/behat-chrome-extension": "^1.4",
"drupal/core-dev": "^10",
"drupal/drupal-extension": "^5@alpha",
"palantirnet/the-build": "^4@beta"
"palantirnet/the-build": "dev-dev-37-eslint"
Comment on lines -36 to +40
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary. After this PR is approved we should be able to revert or update.

},
"suggest": {
"cweagans/composer-patches": "Try ^1.7. Apply patches to packages, especially Drupal.org contrib.",
Expand Down
12 changes: 9 additions & 3 deletions docs/general/drupal_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,17 @@ When you make changes to these files, you will generally need to run `phing buil

### Test Drupal

This project uses Behat to test Drupal; it also provides some PHP linting tools. You can run:
This project uses Behat to test Drupal; it also provides some PHP and Javascript linting tools. You can run:

* All Behat tests: `behat`
* One behat test: `behat features/installation.feature`
* The PHP code review: `phing code-review`
* The PHP + JS code review: `phing code-review`

#### Javascript linting

This project uses [eslint](https://eslint.org/docs/latest/use/) to check custom module js against Drupal js coding standards.

If you'd like to handle your custom module's linting independently, add your module directory to the `/.eslintignore` file and add a command to additionally lint your js to the `code-review` phing target in `build.xml`.

----
Copyright 2020 Palantir.net, Inc.
Copyright 2023 Palantir.net, Inc.
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "palantirnet--drupal-skeleton",
"description": "A Drupal 8 project template.",
"version": "0.0.0",
"devDependencies": {
"check-dependencies": "1.1.0",
"eslint": "8.39.0",
"eslint-plugin-yml": "1.5.0"
},
"dependencies": {
"eslint-config-drupal": "5.0.2",
"npx": "10.2.2"
}
}