Skip to content

Remove forbidden forEach from FE docs

Simon Knox requested to merge psi-allow-foreach into master

What does this MR do?

Remove FE docs advice on avoidance of forEach. Also fix a type in the pure functions code example

Why does it do this?

The example provided would be picked up by our no-param-reassign configuration

forEach has plenty of valid usecases, and often leads to simpler code than an equivalent reduce.

for example:

const marks = editorExtensions
  .filter(extension => extension.type === 'mark')
  .reduce(
    (ms, { name, schema }) => ({
      ...ms,
      [name]: schema,
    }),
    {},
  );
let marks
editorExtensions.forEach(({ name, schema, type }) => {
  if (type === 'mark') {
    marks[name] = schema;
  }
})
Edited by Simon Knox

Merge request reports