Make WordPress Core

Opened 9 years ago

Closed 6 years ago

Last modified 6 years ago

#43828 closed task (blessed) (fixed)

Add JSDoc ESLint script

Reported by: netweb Owned by: netweb
Priority: normal Milestone: 5.5
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch needs-testing
Cc: Focuses: javascript

Description

This script seeks to add a JSDoc focused ESLint script to check the JSDocs conformity with the ​WordPress JavaScript Docs Coding Standards

It will also greatly aid those involved with the ​JavaScript Inline Docs Initiative to ensure patches are conforming to the coding standards.

To test and use this npm script run, npm install and then npm run lint:jsdoc in the terminal console.

A sister pull request add similar functionality has been in ongoing development in the Gutenberg repo:

The patch for this ticket adds the ESLint JSDoc configuration to a file named .eslintrc-jsdoc.js, this is to avoid conflicts with the work in progress of adding ESLint in #31823

Attachments (7)

43828.diff​ (2.2 KB ) - added by netweb 9 years ago.
43828.2.diff​ (1.3 MB ) - added by kamataryo 7 years ago.
This is refreshed patch to do linting script with @wordpress/scripts
43828.3.diff​ (1.7 KB ) - added by kamataryo 7 years ago.
Fixed the broken patch 43828.2.dff
43828.4.diff​ (1.7 KB ) - added by whyisjake 6 years ago.
43828.5.diff​ (205.6 KB ) - added by whyisjake 6 years ago.
43828.6.diff​ (105.4 KB ) - added by whyisjake 6 years ago.
43828.7.diff​ (106.7 KB ) - added by whyisjake 6 years ago.

Download all attachments as: .zip

Change History (33)

#1 @atimmer
9 years ago

  • Keywords has-patch added

This would help a a lot when reviewing patches.

I am thinking, how hard would it be to add a check for the presence of @since?

#2 @netweb
9 years ago

  • Keywords needs-testing added

This patch will need a little more testing to ensure I've excluded, and not errantly omitted any files or folders that we should be checking.

Great idea for @since, I'll take a look around and see what options are available to check that it exists and ensure that it is valid syntax

#3 @jorbin
8 years ago

  • Milestone 5.0 → 5.1

#4 @pento
8 years ago

  • Keywords needs-refresh added
  • Milestone 5.1 → 5.2

#5 @jorbin
8 years ago

  • Milestone 5.2 → 5.3

Bumping this from 5.2 due to lack of progress

This ticket was mentioned in ​Slack in #core-js by kamataryo. ​View the logs.


7 years ago

#7 @kamataryo
7 years ago

Probably we should refresh the patch with [@wordpress/scripts](​https://github.com/WordPress/gutenberg/tree/master/packages/scripts), which includes wp-scripts lint-js.

@kamataryo
7 years ago

This is refreshed patch to do linting script with @wordpress/scripts

@kamataryo
7 years ago

Fixed the broken patch 43828.2.dff

#8 @kamataryo
7 years ago

Sorry to upload 43828.2.diff which is broken and not svn diff.
43828.3.diff should be the minimum required one.

#9 @kamataryo
7 years ago

The patch 43828.3.diff includes:

  • inherit .eslintignore from the existing 43828.diff patch and match it current status
  • inherit .eslingrc.js from the existing 43828.diff patch
  • package.json update to set @wordpress/scripts as a dependency
  • Also npm scripts npm run lint:js is added to run it

#10 @netweb
7 years ago

Thanks @kamataryo, sorry I've not replied sooner, I'll take a look at the latest 43828.3.diff​ patch shortly

#11 @netweb
7 years ago

  • Milestone 5.3 → 5.4

Punting this to 5.4 to help clear the 5.3 milestone

This ticket was mentioned in ​Slack in #core by peterwilsoncc. ​View the logs.


7 years ago

This ticket was mentioned in ​Slack in #core by david.baumwald. ​View the logs.


7 years ago

#14 @netweb
7 years ago

  • Milestone 5.4 → 5.5

Punting this to 5.5 to help clear the 5.4 milestone

#15 @whyisjake
6 years ago

  • Keywords needs-refresh removed

Patch updated @netweb, seems to be working fine.

#16 @netweb
6 years ago

Thanks @whyisjake, might me worth trying this config, though it may have a little too much “Gutenberg” based config

​https://github.com/WordPress/gutenberg/blob/master/packages/eslint-plugin/configs/jsdoc.js

Either or though, no strong opinion so feel free to commit either version 👌🏼

#17 @whyisjake
6 years ago

Updated, and added the "lint:jsdoc:fix": "wp-scripts lint-js --fix", to fix some things automaticaly. There are still 900+ errors, might take some manual cleanup.

#18 @netweb
6 years ago

@whyisjake A quick look at the 43828.5.diff​ I discovered that there are some unwanted changes in the src/wp-includes/nav-menu.php file, the very last file when viewing the patch here on trac:

  • src/wp-includes/nav-menu.php

     
    837837
    838838                                if ( $original_object ) {
    839839                                        $menu_item->url = get_permalink( $original_object->ID );
    840                                         /** This filter is documented in wp-includes/post-template.php */
    841                                         $original_title = apply_filters( 'the_title', $original_object->post_title, $original_object->ID );
    842840                                } else {
    843841                                        $menu_item->url      = '';
    844                                         $original_title      = '';
    845842                                        $menu_item->_invalid = true;
    846843                                }
    847844
    848                                 if ( '' === $original_title ) {
    849                                         /* translators: %d: ID of a post. */
    850                                         $original_title = sprintf( __( '#%d (no title)' ), $menu_item->object_id );
    851                                 }
     845                                $menu_item->title = $menu_item->post_title;
    852846
    853                                 $menu_item->title = ( '' === $menu_item->post_title ) ? $original_title : $menu_item->post_title;
    854 
    855847                        } elseif ( 'post_type_archive' === $menu_item->type ) {
    856848                                $object = get_post_type_object( $menu_item->object );
    857849                                if ( $object ) {

The patch is hard to review here on Trac, I think this is a good candidate to add a PR on GitHub, could you push up a PR and I'll review that there please?

#19 @whyisjake
6 years ago

@netweb, good catch. That came from another patch I was working on.

This ticket was mentioned in ​PR #418 on ​WordPress/wordpress-develop by ​whyisjake.


6 years ago
#20

This is an bring in some changes to automate the testing of JSDoc blocks.

Trac ticket: https://core.trac.wordpress.org/ticket/43828

#22 in reply to: ↑ 21 @netweb
6 years ago

Replying to whyisjake:

@netweb, pull request here: ​https://github.com/WordPress/wordpress-develop/pull/418

Thanks, added some trivial'ish comments to the PR

This ticket was mentioned in ​Slack in #core by david.baumwald. ​View the logs.


6 years ago

#24 @whyisjake
6 years ago

  • Resolution → fixed
  • Status assigned → closed

In 48650:

Build/Test Tools: Enable JSDocs to be linted with ESLint.

As part of the [Javascript Inline Docs Initiative](​https://make.wordpress.org/core/handbook/docs/inline/js/) this add some tooling to lint Javascript docblocks. Two new commands:

  • npm run lint:jsdoc
  • npm run lint:jsdoc:fix

The latter will run the linter and try to fix an possible issues automatically.

Fixes #43828.
Props netweb, atimmer, kamataryo, whyisjake.

#25 @SergeyBiryukov
6 years ago

In 48651:

Docs: Correct alignment for some parameters in JS documentation.

Follow-up to [48650].

See #43828.

Note: See TracTickets for help on using tickets.