Skip to content

Commit

Permalink
Add array-callback-return rule; Fix current code breaking the rule. (#…
Browse files Browse the repository at this point in the history
…14154)

## Description
Adds a rule to make sure Array functions that iterate on the array and should return something contain the return statement, otherwise, a forEach should probably be used instead.
A case like this was fixed at #13953.

In PR #13953 @aduth suggested the implementation of a lint rule to catch these cases. While trying to implement the rule and researching the best ways to do it, I noticed a rule like that already existed in the community and this PR is enabling it.

We are also changing the code to respect the new rule no observable changes should be expected.

## How has this been tested?
Observe the tests pass.
Do some smoke testing, adding blocks, uploading files, and verify everything still works as before.
  • Loading branch information
jorgefilipecosta authored and youknowriad committed Mar 6, 2019
1 parent 2e488f6 commit c152b7c
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/tool/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function getRootManifest( tocFileName ) {

function generateRootManifestFromTOCItems( items, parent = null ) {
let pageItems = [];
items.map( ( obj ) => {
items.forEach( ( obj ) => {
const fileName = Object.keys( obj )[ 0 ];
const children = obj[ fileName ];

Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/file/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const settings = {
transform: ( files ) => {
const blocks = [];

files.map( ( file ) => {
files.forEach( ( file ) => {
const blobURL = createBlobURL( file );

// File will be uploaded in componentDidMount()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class MediaUpload extends Component {
}
if ( ! this.props.gallery ) {
const selection = this.frame.state().get( 'selection' );
castArray( this.props.value ).map( ( id ) => {
castArray( this.props.value ).forEach( ( id ) => {
selection.add( wp.media.attachment( id ) );
} );
}
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Breaking Changes

- The `esnext` and `recommended` rulesets now enforce [`object-shorthand`](https://eslint.org/docs/rules/object-shorthand)
- The `es5` and `recommended` rulesets now enforce [`array-callback-return`](https://eslint.org/docs/rules/array-callback-return)

### New Features

Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/configs/es5.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
rules: {
'array-bracket-spacing': [ 'error', 'always' ],
'array-callback-return': 'error',
'brace-style': [ 'error', '1tbs' ],
camelcase: [ 'error', {
properties: 'never',
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/scripts/check-licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ modules.forEach( ( path ) => {
}, stringDetectedType );
}, detectedType );
}
return detectedType;
}, false );
}

Expand Down

0 comments on commit c152b7c

Please sign in to comment.