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

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

merged 24 commits into from
Aug 16, 2023

Conversation

jesconstantine
Copy link
Contributor

@jesconstantine jesconstantine commented Jun 7, 2023

User story: DEV-37: Use Drupal core JS and CSS linting as default

Description

This PR adds the necessary configuration and scripting to use eslint on our custom js in projects.

Testing instructions

  1. Run composer create-project palantirnet/drupal-skeleton test dev-dev-37-eslint
  2. Follow the updated readme "Quick Start" steps #2-3 to get Drupal installed in your test project: https://github.com/palantirnet/drupal-skeleton/pull/146/files?short_path=b335630#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
  3. Exit your ddev ssh session
  4. Run ddev phing code-review from your host machine
    • Observe that we check for npm dependencies being installed at 2 levels: project and in core.
    • Observe that we install the dependencies.
    • Observe that the code-review passes
  5. Add some bad js to ${drupal.root}/modules/custom/bad-js/bad.es6.js:
    	 const squared = x * x;
    	 const cubed = x * x * x;
    	 console.log('squared =', squared);
    	 console.log('cubed =', cubed);
    
    	 const squared2 = Math.pow(x, 2);
    	 const cubed2 = Math.pow(x, 3);
    	 console.log('squared2 =', squared2);
    	 console.log('cubed2 =', cubed2);
    
    	 const complex = Math.pow(x * 2, 3 + 4);
    	 console.log('complex =', complex);
    
  6. Run ddev phing code-review from your host machine
    • Observe that we check for npm dependencies being installed at 2 levels: project and in core.
    • Observe that we no longer installed the dependencies because we found them already.
    • Observe that the PHP linters still pass
    • Observe that eslint finds errors
    • Observe the step fails as it should.

Notes

This PR relies on palantirnet/the-build#223

@jesconstantine jesconstantine changed the title Use eslint to lint custom javascript DEV-37: Use eslint to lint custom javascript Jun 7, 2023
README.md Outdated Show resolved Hide resolved
.nvmrc Outdated
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!

- 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!

Comment on lines -36 to +45
```
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:
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.

README.md Outdated
Comment on lines 132 to 136
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.

Comment on lines +15 to +18
},
{
"type": "git",
"url": "https://github.com/palantirnet/the-build"
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.

Comment on lines -35 to +39
"palantirnet/the-build": "^4@beta"
"palantirnet/the-build": "dev-dev-37-eslint"
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.

.ddev/commands/web/npx Outdated Show resolved Hide resolved
Comment on lines +1 to +5
#!/bin/bash

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

vendor/bin/phing "$@"
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 ...

@@ -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.

@patrickfweston patrickfweston self-requested a review August 7, 2023 19:14
Copy link

@patrickfweston patrickfweston left a comment

Choose a reason for hiding this comment

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

Everything here works great for me! I think this will help us out a lot on DHS, so I'd be in favor of merging this in. I'm going to hold off until others have a chance to look though.

@patrickfweston
Copy link

I do see there is a test failure, but I'm wondering if we can test that in a different way. I'm not sure how relevant the existing test is.

@byrond byrond merged commit d525245 into develop Aug 16, 2023
@byrond byrond deleted the dev-37-eslint branch August 16, 2023 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants