GithubHelp home page GithubHelp logo

orzechowskid / flymake-eslint Goto Github PK

View Code? Open in Web Editor NEW
39.0 4.0 12.0 48 KB

Flymake backend for Javascript using eslint

License: MIT License

Emacs Lisp 100.00%
emacs flymake flymake-eslint flymake-backend javascript eslint

flymake-eslint's Introduction

flymake-eslint

Flymake backend for Javascript using eslint

MELPA

Installation

  1. Make sure eslint is installed and present on your emacs exec-path. For Linux systems exec-path usually equals your $PATH environment variable; for other systems, you're on your own.
  2. Install:
  • from MELPA: M-x package-install [RET] flymake-eslint [RET]
  • manually: download and place inside ~/.emacs.d/lisp then edit ~/.emacs or equivalent:
(add-to-list 'load-path "~/.emacs.d/lisp")
(require "flymake-eslint.el")
  1. Enable:
(add-hook 'web-mode-hook ; or whatever the mode-hook is for your mode of choice
  (lambda ()
    (flymake-eslint-enable)))

Customization

useful variables are members of the flymake-eslint group and can be viewed and modified with the command M-x customize-group [RET] flymake-eslint [RET].

(defcustom flymake-eslint-executable-name "eslint"
  "Name of executable to run when checker is called.  Must be present in variable `exec-path'."
  :type 'string
  :group 'flymake-eslint)

(defcustom flymake-eslint-executable-args nil
  "Extra arguments to pass to eslint."
  :type 'string
  :group 'flymake-eslint)

(defcustom flymake-eslint-show-rule-name t
  "Set to t to append rule name to end of warning or error message, nil otherwise."
  :type 'boolean
  :group 'flymake-eslint)
  
(defcustom flymake-eslint-defer-binary-check nil
  "Set to t to bypass the initial check which ensures eslint is present.

Useful when the value of variable `exec-path' is set dynamically and the location of eslint might not be known ahead of time."
  :type 'boolean
  :group 'flymake-eslint)

(defcustom flymake-eslint-project-root nil
  "Buffer-local.  Set to a filesystem path to use that path as the current working directory of the linting process."
  :type 'string
  :group 'flymake-eslint)
  
(defcustom flymake-eslint-prefer-json-diagnostics nil
  "Try to use the JSON diagnostic format when runnin ESLint.
This gives more accurate diagnostics but requires having an Emacs
version with JSON support."
  :type 'boolean
  :group 'flymake-eslint)

Bugs

yes

See Also

flymake-stylelint

License

MIT

flymake-eslint's People

Contributors

damiencassou avatar dop avatar hochata avatar orzechowskid avatar simenheg avatar terlar avatar xfa25e avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flymake-eslint's Issues

Melpa?

Could you provide your package on melpa.org?

Thanks!

Can’t initialize automatically with EGLOT

With the setup below I get the following error in my *Messages* buffer: Error in process sentinel: Can’t find state for flymake-eslint—checker in ‘flymake—state’ [2 times]. I do not get this error when I run flymake-eslint-enable manually, though. Is there any workaround or reason as to why this is happening? I have eslint on my PATH and I am using Node version 16.15.1.

(use-package flymake-eslint
:config
    (add-hook 'js-mode-hook (lambda () (flymake-eslint-enable)))
    (add-hook ‘js-mode-hook (lambda () (eglot-ensure))) ;; this will be run first
)

The eglot-ensure will run first. If I try and switch the order, eglot decides to override the flymake backends, making eglot the only backend. I can then run flymake-eslint-enable, but that defeats the purpose of what I want…If I remove the eglot line altogether, then this package works as intended, still not what I want…I am enabling js-mode manually in all these tests.

When using a eslint binary installed locally with direnv it doesn't work

If by chance flymake-eslint-enable happens to execute before the hook that adds the direnv things to path it will fail to enable flymake-eslint. I have run into this where I add (eval . (flymake-eslint-enable)) to a .dir-locals.el file. At the time where the check for the binary is run it is not available yet. If I later run the command it will of course work. Perhaps it should be possible to add the checker to flymake-diagnostic-functions even though the binary is not available.

Either make this behavior configurable or perhaps add the check for the binary to a later stage, e.g. during the checking, as a pre-condition or similar.

Allow running ESLint using npx

Currently, ESLint needs to be in executable-path, which means that ESLint must be installed globally or executable-path has to be configured per project. It would be nice if flymake-eslint would offer the possibility to run ESLint through NPM's npx command instead (npx eslint), which would automatically pick up the ESLint version installed in the project's node_modules, and only runs the globally installed version as a fallback.

Flymake crashes with "Unexpected report from disabled backend"

This is an incomplete bug report as I don't know what's causing the problem.

As soon as I'm causing a linting violation in a file (and save that file), the following is printed to *Messages*:

error in process sentinel: flymake-error: [Flymake] Unexpected report from disabled backend flymake-eslint--checker
error in process sentinel: [Flymake] Unexpected report from disabled backend flymake-eslint--checker

Trying to go to the next error fails with the following message:

user-error: No more Flymake diagnostics

flymake-eslint is in my package-selected-packages in my init file. I'm using the following config:

(setq exec-path (append exec-path '("/path/to/project/node_modules/eslint/bin")))
(setq flymake-eslint-executable-name "/path/to/project/node_modules/eslint/bin/eslint.js")
(add-hook 'js-mode-hook (lambda ()
                          (flymake-eslint-enable)))
(add-hook 'js-mode-hook
	      (lambda()
	        (local-set-key (kbd "C-c C-f") 'flymake-goto-next-error)))

I'm using [email protected] and node version v16.9.1 with GNU Emacs 27.2 on Manjaro. I'm not sure what additional information to provide. Please tell me.

`flymake-eslint-enable` works when enabled from minibuffer but fails when started from major mode hook

Here's my config

(use-package flymake
  :ensure flymake
  :demand
  :hook (prog-mode . flymake-mode)
  :defines
  flymake-mode
  :bind
  ("M-n"     . flymake-goto-next-error)
  ("M-p"     . flymake-goto-prev-error)
  ("<f12>"   . flymake-goto-next-error)
  ("C-<f12>" . flymake-goto-next-error)
  ("C-c !"   . flymake-show-buffer-diagnostics))

(use-package flymake-eslint
  :ensure flymake-eslint
  :after (flymake)
  :hook
  (js2-mode . flymake-eslint-enable)
  (web-mode . flymake-eslint-enable)
  (typescript-ts-mode .  (lambda () (flymake-eslint-enable)))
  (tsx-ts-mode . (lambda () (flymake-eslint-enable))))

If I open a ts or tsx file and then I do M-x flymake-eslint-enable it works
But as a hook trigger from the above config it fails

Note: It's now written with lambda as I hoped that would solve it but I get the same error if have hooks configured like

(mode . flymake-eslint-enable)

I'm using treesitter & eglot

Messages Log

error in process sentinel: flymake--handle-report: Can’t find state for flymake-proc-legacy-flymake in ‘flymake--state’
error in process sentinel: Can’t find state for flymake-proc-legacy-flymake in ‘flymake--state’
error in process sentinel: flymake--handle-report: Can’t find state for flymake-eslint--checker in ‘flymake--state’
error in process sentinel: Can’t find state for flymake-eslint--checker in ‘flymake--state’

Is it possible to run it from project's root?

My eslint configuration file has the parserOptions.project property defined to ./tsconfig.json.

This breaks when flymake-eslint runs eslint because, if I'm not mistaken, it does so from the directory containing the file the buffer is visiting as there's no ./tsconfig.json there (but some directories up).

Error reported when running flymake-eslint-enable is

/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/miau.ts
  0:0  error  Parsing error: File '/home/marcos/Projects/Sandbox/flymake-eslint-error/test/foo/bar/tsconfig.json' not found

✖ 1 problem (1 error, 0 warnings)```

Any hint on how to workaround it or fixing guidelines will be appreciated.

Thanks!

GPL?

Would like to know why the package is released under MIT?

Using `buffer-name` causes potential errors

buffer-name does not always return the actual file-name. If you have multiple buffers with the same conflicting name it could be renamed, as well as personally I have custom code displaying different buffer-name based on project.

E.g.

(defun +projectile-relative-buf-name ()
  (when (buffer-file-name)
    (let ((buffer-name (if (projectile-project-p)
                           (concat (projectile-project-name) "/" (file-relative-name (buffer-file-name) (projectile-project-root)))
                         (abbreviate-file-name (buffer-file-name)))))
      (rename-buffer buffer-name t))))
(add-hook 'find-file-hook #'+projectile-relative-buf-name)

In those cases you will get, since the buffer-name is passed as --stdin-filename:

Error: ENOENT: no such file or directory, scandir '/path/to/src/code'

One work-around is to instead use buffer-file-name which will give the absolute path to the file.

project-root void error

On emacs 27.2 project-root function not available. Can be fixed by installing project package from GNU ELPA.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.