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

Issue fork drupal-2924755

Command icon 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

xjm created an issue. See original summary.

xjm’s picture

Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new611 bytes
xjm’s picture

Title: Set max line length to JavaScript to 80 (rather than 100) » Set max line length for JavaScript to 80 (rather than 100)

Prepositions are hard.

Status: Needs review » Needs work

The last submitted patch, 2: js-comment-line-length.patch, failed testing. View results

xjm’s picture

Title: Set max line length for JavaScript to 80 (rather than 100) » Set max line length for JavaScript code comments to 80 (rather than 100)
Status: Needs work » Needs review
StatusFileSize
new602 bytes

Let's try a diff against HEAD instead of my local branch.

wim leers’s picture

Issue tags: +JavaScript, +Coding standards

I had this exact discussion with @drpal. He pointed out that if Drupal's JS coding standards are airbnb, except for this one thing, 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.

xjm’s picture

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

wim leers’s picture

we're already overriding a number of things from the AirBnB standard

Oh … that wasn't the case yet when I first raised that very same point, when that standard was being introduced.

Ignore #6 then! :)

droplet’s picture

Sounds like the deal already made. But NO editors have 2 lines to indicate 80 & 100 cols separately.

we're already overriding a number of things from the AirBnB standard

It doesn't a good point. The breaking changes were forced to move forward rather than well-discussed.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: -JavaScript +JavaScript, +Novice

This will need to be updated for D10

Tagged for novice for beginner developers.

_utsavsharma’s picture

StatusFileSize
new625 bytes
new625 bytes

Patch for 10.1.x.

rifas-ali-pbi made their first commit to this issue’s fork.

prem suthar’s picture

Status: Needs work » Needs review
quietone’s picture

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

smustgrave’s picture

Status: Needs review » Needs work

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

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gauravvvv’s picture

Status: Needs work » Needs review
StatusFileSize
new1.21 KB
new617 bytes

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

Desktop/dev/drupal/core/misc/ajax.js
    9:1  error  This line has a comment length of 215. Maximum allowed is 80  max-len
  227:1  error  This line has a comment length of 82. Maximum allowed is 80   max-len
  330:1  error  This line has a comment length of 88. Maximum allowed is 80   max-len
  616:1  error  This line has a comment length of 82. Maximum allowed is 80   max-len
  828:1  error  This line has a comment length of 99. Maximum allowed is 80   max-len
smustgrave’s picture

Status: Needs review » Needs work

Sam Phillemon made their first commit to this issue’s fork.

Sam Phillemon’s picture

I 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:

/Users/sam/workspace/project/drupal/core/modules/views_ui/js/views-admin.js
   224:1  error  This line has a length of 82. Maximum allowed is 80  max-len
   239:1  error  This line has a length of 81. Maximum allowed is 80  max-len
   537:1  error  This line has a length of 82. Maximum allowed is 80  max-len
   538:1  error  This line has a length of 81. Maximum allowed is 80  max-len
   547:1  error  This line has a length of 91. Maximum allowed is 80  max-len
   568:1  error  This line has a length of 82. Maximum allowed is 80  max-len
   742:1  error  This line has a length of 81. Maximum allowed is 80  max-len
   770:1  error  This line has a length of 83. Maximum allowed is 80  max-len
   849:1  error  This line has a length of 82. Maximum allowed is 80  max-len
   937:1  error  This line has a length of 82. Maximum allowed is 80  max-len
  1027:1  error  This line has a length of 82. Maximum allowed is 80  max-len
  1030:1  error  This line has a length of 82. Maximum allowed is 80  max-len
Sam Phillemon’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

"The source branch is 2480 commits behind the target branch."

needs a rebase.

Sam Phillemon’s picture

Status: Needs work » Needs review

I have rebased the branch as well. Now it is up to date.

smustgrave’s picture

Status: Needs review » Needs work

Left a comment. Probably fine to self RTBC after the one change.

Sam Phillemon’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We need to update the .gitlab-ci.yml file we need to add core/.eslint* to the list of changes in '🧹 JavaScript linting (eslint)':

      changes:
        - core/package.json
        - core/yarn.lock
        - "**/*.js"
        - "**/*.yml"
alexpott’s picture

See 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

Sam Phillemon’s picture

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

alexpott’s picture

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

Sam Phillemon’s picture

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

rodrigoaguilera’s picture

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

xjm’s picture

Issue summary: View changes
Issue tags: +Nara2025

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

gengo_k’s picture

Our team will try to find out what this issue is.

gengo_k’s picture

Issue summary: View changes
shumpei’s picture

Working on this issue at as a member of DrupalCon Nara Contribution Day.

yosuke taniguchi’s picture

Working on this issue at as a member of DrupalCon Nara Contribution Day.

terao3’s picture

Working on this issue at as a member of DrupalCon Nara Contribution Day.

tnakai made their first commit to this issue’s fork.

tnakai’s picture

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

gengo_k’s picture

MR has been updated. We have checked the change itself is fine.
The next step is to fix JS files using --fix option (mentioned by #42).
However, we could not reach the way to fix all files, which has over 80 characters comment.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

tom konda’s picture

The next step is to fix JS files using --fix option (mentioned by #42).

The max-len rule isn't support --fix option, need to fix manually.
If a rule is supporting --fix option, 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.

tom konda’s picture

Remaining error code comments are mainly categorized to 3 types.

1. JSDoc type name
2. cspell ignore settings
3. Code example