Problem/Motivation
The AirBnB standards specify avoiding line length of more than 100 characters:
https://github.com/airbnb/javascript#whitespace--max-len
However, core's line length is 80 characters (required for comments and loosely followed for code when possible).
@drpal pointed out that our JS can have separate documentation standards than PHP, which makes sense, However:
- This particular rule is very ingrained for Drupal (because of our IDE configurations, window settings, etc.) and already widely used in our JS.
- We still usually ask contributors to wrap lines at 80 characters. E.g. in #2924351: Fix coding standards issues with existing settings tray JavaScript, @drpal also started rewrapping docblocks to 80.
- It's always best for the coding standards we ask of contributors to be automatically enforced by our ruleset, so contributors can rely on tools rather than memory and don't get seemingly arbitrary reviews on their codestyle.
- A shorter line length of up to 80 characters still complies with a recommended length of no more than 100 characters. :)
Proposed resolution
Update the ruleset to override this rule to 80 characters rather than 100.
Remaining tasks
Review the MR.
Fix the 400-some lines that are too long (see #42).
(Maybe) update coding standard (Add fix command above).
testing
Attached patch tries to implement this by copying from https://github.com/airbnb/javascript/blob/7ff6303513b46e8b7dd0bc03327b13... but adding a shorter line length for comments.
I couldn't figure out how to just add the "comment" key and let the rest inherit from the AirBnB ruleset, but maybe there's a way to do that.
This is what an overlong line says in HEAD:
146:1 error Line 146 exceeds the maximum line length of 100 max-len
With the patch you get two types of messages:
146:1 error Line 146 exceeds the maximum line length of 100 max-len
187:1 error Line 187 exceeds the maximum comment line length of 80 max-len
| Comment | File | Size | Author |
|---|
Issue fork drupal-2924755
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
xjmComment #3
xjmPrepositions are hard.
Comment #5
xjmLet's try a diff against HEAD instead of my local branch.
Comment #6
wim leersI had this exact discussion with @drpal. He pointed out that if Drupal's JS coding standards are , then it's no longer the airbnb coding standard, but Drupal's own coding standard.
So, for the sake of avoiding A) bikeshedding, B) not having Drupal-specific JS coding standards, we went with the airbnb coding standards, without any exceptions.
Comment #7
xjm@Wim Leers, as discussed with @drpal (we talked about this last week), we're already overriding a number of things from the AirBnB standard. So #6 is not entirely true.
We don't need to invent Drupalism standards, add arbitrary formatting preferences for docblocks, or conflict with the AirBnB standard, but documentation line length is going to get flagged in issues over and over and thus create a disruptive contribution experience for JS contributors. Whereas if it's just a slightly tweaked version of AirBnB's rule (that still complies), all that matters is that you can check it automatically.
AirBnB specifies a line length of 100, but does not specify the specific comment line length rule.
Comment #8
wim leersOh … that wasn't the case yet when I first raised that very same point, when that standard was being introduced.
Ignore #6 then! :)
Comment #9
droplet commentedSounds like the deal already made. But NO editors have 2 lines to indicate 80 & 100 cols separately.
It doesn't a good point. The breaking changes were forced to move forward rather than well-discussed.
Comment #20
smustgrave commentedThis will need to be updated for D10
Tagged for novice for beginner developers.
Comment #21
_utsavsharma commentedPatch for 10.1.x.
Comment #23
prem suthar commentedComment #24
quietone commented@rifas-ali-pbi, The issue is using a patch based work flow and creating a fork is not needed. Therefor, credit has been removed per How is credit granted for Drupal core issues.
What pages, if any, of the JavsaScript coding standards need to be updated.
Has this change been tested on Drupal 10?
Comment #25
smustgrave commentedTried testing by editing ajax.js
Extending a comment to 85 characters and running code-commit-check it didn't flag it.
So not sure why it's not working.
Comment #27
gauravvvv commentedWe need to modify the .eslintrc.passing.json file as well with the max-len. I have updated the file and now it is working as expected. Attached interdiff for same.
Comment #28
smustgrave commentedComment #31
Sam Phillemon commentedI have added the changes suggested in #27 in the file '.eslintrc.passing.json'. Also, I am seeing a lot of files get affected because of this max-len check. I am unsure whether this needs to be fixed as part of this issue or if it needs to be taken care of separately. It would be great if someone could suggest what approach is required. Below is just a sample of how the error looks for one of the files:
Comment #32
Sam Phillemon commentedComment #33
smustgrave commented"The source branch is 2480 commits behind the target branch."
needs a rebase.
Comment #34
Sam Phillemon commentedI have rebased the branch as well. Now it is up to date.
Comment #35
smustgrave commentedLeft a comment. Probably fine to self RTBC after the one change.
Comment #36
Sam Phillemon commentedComment #37
alexpottWe need to update the .gitlab-ci.yml file we need to add
core/.eslint*to the list of changes in'🧹 JavaScript linting (eslint)':Comment #38
alexpottSee how the eslint job now would fail the moment we have a js change in an issue... https://git.drupalcode.org/issue/drupal-2924755/-/jobs/1402860
Comment #39
Sam Phillemon commented@alexpott - I've made the suggested changes to the .gitlab-ci.yml file, but unfortunately, the eslint job is still failing. Could you kindly confirm whether the proposed changes are correct or if there's something I might be overlooking?
Comment #40
alexpott@Sam Phillemon the eslint job is failing because you've changed the rules and the code is no longer compliant. So the js code needs fixing... The build was green before because the eslint job was not running when it should because you're changing the eslint files.
Comment #41
Sam Phillemon commented@alexpott Ah, now I understand what you're saying. It caught me off guard a bit when I noticed the build was green. Thank You!
I've noticed a significant number of files have been affected by this max-len check (as mentioned in #31), and I'm unsure whether resolving this should be included in this particular issue or handled separately. Therefore, I'm uncertain about the appropriate procedure.
Comment #42
rodrigoaguileraNow that the rule is changed to 80 now is about to fix all the instances.
Have a look at the "fix" command for eslint
https://eslint.org/docs/latest/use/command-line-interface#options
The Drupal Contribution Mentoring team is triaging issues for Drupalcon Vienna 2025, and we are reserving this issue for Mentored Contribution during the event.
After 17th of October, this issue returns to being open to all. Thanks!
Comment #43
xjmStill a good contributor task for Nara. 😀 Updating the remaining tasks in the issue summary with a reference to #42.
The Drupal Contribution Mentoring team is triaging issues for DrupalCon Nara 2025, and we are reserving this issue for Mentored Contribution during the event.
After November 19, this issue returns to being open to all. Thanks!
Comment #44
gengo_kOur team will try to find out what this issue is.
Comment #45
gengo_kComment #46
shumpei commentedWorking on this issue at as a member of DrupalCon Nara Contribution Day.
Comment #47
yosuke taniguchi commentedWorking on this issue at as a member of DrupalCon Nara Contribution Day.
Comment #48
terao3 commentedWorking on this issue at as a member of DrupalCon Nara Contribution Day.
Comment #50
tnakai commentedThe max-len for yaml was being enabled, so I turned it off by the commit above. The max-len for JS still need to be worked on.
Comment #51
gengo_kMR has been updated. We have checked the change itself is fine.
The next step is to fix JS files using
--fixoption (mentioned by #42).However, we could not reach the way to fix all files, which has over 80 characters comment.
Comment #53
tom kondaThe max-len rule isn't support
--fixoption, need to fix manually.If a rule is supporting
--fixoption, rule has meta.fixable property but max-len not.FYI:
The max-len rule is deprecated since ESLint v8.53.0.
Need to use @stylistic/eslint-plugin in near the future.
Comment #54
tom kondaRemaining error code comments are mainly categorized to 3 types.
1. JSDoc type name
2. cspell ignore settings
3. Code example