17

The warning comes from JS2 Mode which implements its own parser for Javascript and warns about a couple of issues. As noted in the other answer the particular warning you observed is controlled by the user option js2-strict-missing-semi-warning which you can set to nil in your init file or via M-x customize so as to turn off the warning. When using JS2 ...


12

There is a trailing quotation mark in your regular expression, so it will never match files with the .js extension. Use the following regular expression instead: (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) Note the absence of the dollar—which matches the end of a line rather than of the string—and the backslash before the quotation mark: \\' ...


5

Thanks to @Dmitry's comment above, I was able to resolve this issue by configuring the default plugins for Tern. In the tern file from the repo under bin/tern, I edited the default plugins here: var defaultConfig = { libs: [], loadEagerly: false, plugins: {"commonjs":{}, "node":{}, "requirejs":{}, "node_resolve":{}}, ecmaScript: true, ecmaVersion:...


4

Perhaps there is a dot-file that I can add to my project's root folder where I can configure settings? Yes. It is called "Per-Directory Local Variables" aka ".dir-locals.el". Create a file named .dir-locals.el in the project root directory and have project specific configurations in it. More info (https://www.emacswiki.org/emacs/DirectoryVariables) You ...


3

It turned out that my personal config (and those of the people I tested this with) manually bound C-m to c-context-line-break in js-mode. So the right answer is to not do this (and leave it as newline-and-indent.) Silly me. Original "workaround": The looking-at(nil) gave a pretty good hint that this was a cc-mode regex left unset by js-mode and js2-mode. ...


3

Maybe you could try to use SPC p R which runs the command projectile-replace this might not be exactly what you want (a specific js refactor tool) but it gets the job done and is language agnostic. Another more advanced option would be to search the name of that function with helm, once you are in the helm buffer C-c C-e runs helm-ag-edit, this will give ...


3

Flycheck can use many different Javascript linters, including but not limited to eslint, which report far more issues that just syntax errors and strict-mode issues. For instance eslint can warn you about useless super() calls in ES6 constructors, and help you enforce the use of const in ES6 code, or warn about using var instead of let in ES6. If you can ...


3

It seems that the variable you want to set is js2-global-externs. js2-additional-externs is intended for setting globals on per-buffer basis, not for all buffers with js2-mode.


3

The variable responsible for this is js2-strict-inconsistent-return-warning. Just set it to nil.


3

In addition to what @wasamasa said, js2-mode derives from js-mode and shares its indentation engine. Thus, fixing an indentation bug in js-mode fixes it in js2-mode as well.


3

TL;DR: M-x package-refresh-contents and try again :) Emacs tells you that a package was not found on the remote archive. This is a symptom of an outdated local package archive cache: Your Emacs tries to fetch an outdated version of a package which does not exist on the server anymore because a never package is already available. You can refresh the local ...


3

Solution 1 (recommended): A perfect solution for BOTH js-mode and js2-mode: https://github.com/redguardtoo/emacs.d/blob/master/lisp/init-javascript.el Screen shot, Solution 2 (js2-mode only): It's a little bit more complex to set up, but the imenu item will display more context and I GUESS imenu functions extracted this way could be hide/show by js2-...


2

It looks like you're expecting js2-minor-mode to handle your indentation? That's not the case. C-hf js2-minor-mode RET js2-minor-mode is an interactive autoloaded Lisp function in `js2-mode.el'. (js2-minor-mode &optional ARG) Minor mode for running js2 as a background linter. This allows you to use a different major mode for JavaScript editing, such ...


2

js2-mode does not use jshint, it will do the syntax check in elisp.


2

You could customize the js2-strict-missing-semi-warning variable to nil so that it it doesn't warn you for this particular problem, or you could use js-mode instead of js2-mode. Of the two options, I recommend changing your style guide; automatic semicolon insertion in JS is a trap. Still, I recognize that that might not always be possible.


2

The right thing to do is to run this tern-get-type from eldoc-documentation-function. This way, eldoc-mode will take care of running it after a little delay etc... I.e. maybe something like (defun js2--eldoc-via-tern () ...(tern-get-type..)...) (add-hook 'js2-mode-hook (lambda () (setq-local eldoc-documentation-function #'js2--...


2

It warns you that the key variable is undeclared, and using it like this, you leak it into the global namespace. Try this is your browser console: > let foo = {bar: 1}; > for(key in foo) {} > key => "bar"


2

I've found a solution using the emacs package mmm-mode. Most of the information I got was from this article. What this package does, is allow multiple major modes in the same buffer. You basically set the opening and closing clauses for whatever nested syntax you have, and that block will be highlighted in a submode. M-x package-install RET graphql-mode M-...


2

You can use the variable major-mode to find out the current Major Mode. The value is a Symbol, thus you can compare it using eq. (defun toggle-between-web-mode-and-js2-jsx-mode () (interactive) (cond ((eq major-mode 'web-mode) (js2-jsx-mode)) ((eq major-mode 'js2-jsx-mode) (web-mode)))) (interactive) is required to make the function as an Emacs ...


2

js-mode supports the minor mode semantic-mode. You can activate it with M-x semantic-mode. M-x imenu-add-to-menubar RET Index RET adds a menu item "Index" to the menu bar with submenus Functions and Variables. You can activate semantic mode by default with the following lines in your init file: (defun js-setup-semantic () "Setup semantic mode for js." (...


1

I suddenly ran onto org-src-lang-modes, whereas the following snippet solved the problem: (add-to-list 'org-src-lang-modes '("js" . js2) )


1

ElDoc When eldoc-mode is enabled it checks whether eldoc-documentation-function is defined in current buffer. If not - it messages "There is no ElDoc support in this buffer" and exits. Neither of these modes supports ElDoc, i.e. doesn't implement eldoc-documentation-function. Company When new characters are typed, company after each command checks for a ...


1

There's the js2-refactor package which does many things but doesn't rename functions. Perhaps you could extend it.


1

If you use flycheck and js2-mode, the error is shown by js2-mode not by flycheck. You can disable js2-mode errors by setting (setq js2-mode-show-parse-errors nil) (setq js2-mode-show-strict-warnings nil)


1

Using use-package you can ensure it'll be available to your emacs. Here is my snippet: (use-package prettier-js :after js2-mode :init (add-hook 'js2-mode-hook 'prettier-js-mode) (add-hook 'web-mode-hook 'prettier-js-mode) :config (setq prettier-js-args '("--trailing-comma" "all" "--bracket-spacing" "false")) (defun ...


1

You need to have the program prettier installed on your system. See git repo here. After you have done this, use following code in your init.el: (require 'prettier-js) (add-hook 'js2-mode-hook 'prettier-js-mode) (add-hook 'web-mode-hook 'prettier-js-mode) Only if that is working you can think about replacing the above lines with a use-package definition.


1

Use-package is designed NOT to stop on error. All errors are reported in the *Warnings* buffer. This way you can almost always start your emacs and fix any errors from within Emacs. From use-package README https://github.com/jwiegley/use-package: Additionally, if an error occurs while initializing or configuring a package, this will not stop your ...


1

So this was due to auto-fill-mode. I was under the mistaken impression that comment-auto-fill-only-comments would make auto-fill-mode only apply to comments, but actually it seems like it only applies to comment-indent-new-line. The problem is that in js2-mode this is set: (set (make-local-variable 'comment-line-break-function) #'js2-line-break) Then ...


1

fill-column immediately becomes buffer-local when set. So, when your config is evaluated, that buffer's fill-column is set... but then nothing else happens. If you set it with a hook, then fill-column will be set any time that hook is fired -- that is, every time a new buffer is created in js2-mode, and then fill-column will be set for that buffer. You can,...


1

After many attempts to get rid of undefined... I ended up using a shell command and send all my Javascript to node and return just the result instead of a console. If you are interested here is the code. (define-key js-mode-map (kbd "C-c C-c") #'(lambda () (interactive) (shell-command-on-region (point-min) (point-max) "node")))


Only top voted, non community-wiki answers of a minimum length are eligible