6

Sometimes I'd like to know if the code I'm writing is ES5 compliant/safe or not.

Example: this would fail because of the arrow function.

() => "something";

I know Babel could take care of this. But sometimes I would like to test some cases.

Is there a place where I could do this?

cbdeveloper
  • 27,898
  • 37
  • 155
  • 336

1 Answers1

9

Try ESlint, https://eslint.org/demo. You can disable advanced rules and stick to the basics.

For example, with an arrow function on ES5: https://eslint.org/demo#eyJ0ZXh0IjoiKCkgPT4gXCJzb21ldGhpbmdcIjsiLCJvcHRpb25zIjp7InBhcnNlck9wdGlvbnMiOnsiZWNtYVZlcnNpb24iOjUsInNvdXJjZVR5cGUiOiJzY3JpcHQiLCJlY21hRmVhdHVyZXMiOnt9fSwicnVsZXMiOnt9LCJlbnYiOnt9fX0=

It could also be automated as part of a build/ci script.

rkouye
  • 493
  • 3
  • 12
  • This partially worked. It works well for syntax. But the code `someString.someUndefinedMethod(whatever)` does not show any errors. It's not aware of ES5 prototype methods. [Link](https://eslint.org/demo#eyJ0ZXh0IjoidmFyIHggPSBcInNvbWVTdHJpbmdcIjtcblxueC5zb21lVW5kZWZpbmVkTWV0aG9kKFwiYWFhYVwiKTsiLCJvcHRpb25zIjp7InBhcnNlck9wdGlvbnMiOnsiZWNtYVZlcnNpb24iOjUsInNvdXJjZVR5cGUiOiJzY3JpcHQiLCJlY21hRmVhdHVyZXMiOnt9fSwicnVsZXMiOnt9LCJlbnYiOnt9fX0=) – cbdeveloper Feb 17 '20 at 09:23
  • @cbdeveloper due to the nature of JS, methods are not type-checked. As far as I know, there is no rule for that in ESLint. Unless you are using a type-checking compiler like [typescript](https://www.typescriptlang.org/play/index.html#code/MYewdgzgLgBAtgUwhAhgcwQLhtATgSzDRgF4YByACwQBsaQYB3EXGgE3IG4AoRZdBADoIIRAFUwbBADNCCNgFkEUSiDYAKAJTdQkEDSH006vqgybOQA), there is no way to know if `someUndefinedMethod` was not defined by a third party library for example. – rkouye Feb 17 '20 at 09:40
  • You are right! I think I need an ES5 environment to actually (try to) run some code . Thanks – cbdeveloper Feb 17 '20 at 09:52