New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[JavaScript Linting] Support ESNext (async/await, class properties, etc) #3160
Comments
This is a good idea and also needed for #3180. |
Pleaaaase work on this issue. |
New JSHint version 2.10.0 has been released with support for the new features. |
As temp workaround - I've used ACE typescript, it already have await/async. |
Typescript doesn't show an error.. but then it misses a lot of other errors. |
its not just async/await its all es6 syntax including new math operators like |
As of today, this issue is 3 years old. React has been out awhile now so surely the demand is increasing for this. The project is still pretty active, but there is no indication of this being on any official roadmap and just seems like it's a, "yea that's what we need to do, and we're probably gonna do it." Can we please get some sort of update here? @nightwing ? @adamjimenez ? |
I found this while trying to find the linter for CSS files, and jury rig something of my own, /mode/javascript_worker.js 🔗 This config seems to suggest that it is already set up for ESNext support |
I tried re-building ace after replacing the jshint.js file with the latest. This prevents an error being shown for async/await. However it also stops errors being shown for other scenarios (missing brackets, unclosed strings, etc). Very frustrating, I suppose the ace project is dead. |
I've been fiddling with this too and I was able to make it work. Documentation could be updated, it was rather painful to dig out how the whole ecosystem works (took several hours) and then learned that all change was needed is one line... :/ There are a couple of options:
UPDATE: Since my last comment found another way:
|
Awesome!! Any indication if you could specify other versions, like 6 for ES6 and so on? I'll also add, in case others are new to git or haven't set up their SSH with Github, you can also clone it with: |
Is @sharq88 method still can be used on the latest ACE? |
Hi @dreamsavior, you can't use AFAIK jshint can't know if you're using js modules or commonJS, because it has no configuration for this, you can check in jshint configuration, so it's not an ACE problem, it's a jshint problem. It's a sad ECMA definition, because node.js (in some cases) and chrome supports direct node eval. node -e "console.log(new Date()); await new Promise(r=>setTimeout(r,1000));console.log(new Date());"
[eval]:1
console.log(new Date()); await new Promise(r=>setTimeout(r,1000));console.log(new Date());
^^^^^
SyntaxError: await is only valid in async functions and the top level bodies of modules
at new Script (node:vm:100:7)
at createScript (node:vm:257:10)
at Object.runInThisContext (node:vm:305:10)
at node:internal/process/execution:75:19
at [eval]-wrapper:6:22
at evalScript (node:internal/process/execution:74:60)
at node:internal/main/eval_string:27:3 node with package.json with cd /tmp
mkdir await_test
cd await test
echo '{"type": "module"}' > package.json
echo "console.log(new Date()); await new Promise(r=>setTimeout(r,1000));console.log(new Date());" > index.js && node .
2021-12-26T16:32:51.557Z
2021-12-26T16:32:52.564Z direct node execution node
Welcome to Node.js v16.13.1.
Type ".help" for more information.
> console.log(new Date()); await new Promise(r=>setTimeout(r,1000));console.log(new Date());
2021-12-26T16:34:30.794Z
2021-12-26T16:34:31.797Z
undefined
> As you can see, the behavior is not standard... so there is no way to know if you can or can't use Regards. EDIT: if your code is correct you can always use jshint directives from documentation // Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */
ignoreThis(); // jshint ignore:line |
@chumager |
As specified above, JSHint has been updated to support these new language features and in order to enable it you need to add the following code
|
You guys should just set the default esversion higher for the linter. What kind of JS dev isn't using async/await in 2022? It took me half an hour to find out how to do it by finally finding this issue. |
In case anyone else finds this thread whilst googling for this issue in react (using react-ace) do the following: const mode = 'javascript';
const onLoad = ({session}: Ace.Editor) => {
// Allow the latest js features in the editor, see https://github.com/ajaxorg/ace/issues/3160.
// AceEditor does not seem to expose any of the js worker options, using a similar approach to this works.
if (mode === 'javascript') {
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-ignore
if (session.$worker) {
// @ts-ignore
session.$worker.send('setOptions', [{
'esversion': 11,
'esnext': false,
}]);
}
}
}
<AceEditor
mode={mode}
onLoad={onLoad}
/> And thanks @sharq88 for the fix 👍 |
I'm suggesting to change the javascript hinting to use ESLint for better support of ES6+ features.
I'd like to be able to use class properties and async/await the most, but there are also tons of other linting rules that it does much better than jshint.
I haven't looked into how difficult this might be to swap out the javascript linter, so I don't know how realistic of a request this is.
The text was updated successfully, but these errors were encountered: