espree icon indicating copy to clipboard operation
espree copied to clipboard

Proposal: errors option

Open mysticatea opened this issue 7 years ago • 5 comments

Purpose: There are recoverable errors in syntax error, e.g. duplicate names, invalid escapes in RegExp, and etc. ESLint stops all linting if it encountered those recoverable errors. However, ESLint should be able to work.

Proposal: Adds errors option to espree.

const ast = espree.parse(code, { errors: true })
console.log(ast.errors) //→ Array of recoverable errors.

acorn reports errors by this.raiseRecoverable() method if the error is recoverable. If the errors:true option is given, espree collects recoverable errors into ast.errors property instead of throwing exception.

Then ESLint can report the ast.errors to users.

mysticatea avatar Feb 14 '18 22:02 mysticatea

I'm a bit concerned that this would make it more difficult to write rules, because the rules would need to have a reasonable behavior for impossible ASTs. (For example, this could create other issues like https://github.com/eslint/eslint/issues/7712.)

not-an-aardvark avatar Feb 16 '18 22:02 not-an-aardvark

Yes, you are right. Using this errors option will be a breaking change for ESLint. I will make a PR to update core rules if this is accepted.

mysticatea avatar Feb 17 '18 01:02 mysticatea

@not-an-aardvark Is that necessarily the case? Could we instead augment parseForESLint to support an AST errors property, and just report errors without linting if errors are present?

platinumazure avatar Feb 24 '18 17:02 platinumazure

We could do that. I was under the impression that the goal was to be able to run rules when there are non-fatal errors.

not-an-aardvark avatar Feb 24 '18 18:02 not-an-aardvark

You might be right. I was thinking that we could at least report multiple parser errors, when they are "recoverable". We'll have to see what @mysticatea thinks.

On Feb 24, 2018 13:11, "Teddy Katz" [email protected] wrote:

We could do that.I was under the impreaaion that the goal was to be able to run rules when there are non-fatal errors.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eslint/espree/issues/368#issuecomment-368247675, or mute the thread https://github.com/notifications/unsubscribe-auth/AARWerKL6myPvL9tyCrxwnJepA-2pQLwks5tYFDNgaJpZM4SGEvs .

platinumazure avatar Feb 24 '18 20:02 platinumazure