Fixing Spacemacs, smart search does not ignore node_modules
Using Spacemacs as Javascript backend development IDE, I needed to make following changes.
- install tern, eslint, eslint-plugin-jest, jsonlint, standard npm packages globally.
- enable javascript layer
- Using spacemacs, the “smart search” function doesn’t exclude node_modules. After trying for awhile, I updated the dotspacemacs-search-tools, switched to Ack. Smart search started to ignore node_modules.
- add .tern-project in the project root directory
- add .eslintrc in the project root directory
npm install -g eslint eslint-plugin-jest tern jsonlint standard
dotspacemacs-configuration-layers
'(
git
markdown
syntax-checking
version-control
html
javascript
..
;; updated the search tools order to ack first.
dotspacemacs-search-tools '("ack" "ag" "pt" "grep")
(defun dotspacemacs/user-init ()
;; to tell js2-mode that we are working with node modules
(setq js2-include-node-externs t)
.tern-project file:
{
"libs": [ ],
"loadEagerly": false,
"plugins": {
"commonjs": {},
"node": {},
"requirejs": {},
"node_resolve": {}
}
}
.eslintrc.json
{
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true,
"jest/globals": true
},
"plugins": ["jest"],
"extends": [
"eslint:recommended",
"plugin:jest/recommended"
],
"globals": {
"process": "readonly",
"exports": "writable"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-console": "off",
"no-process-env": "off",
"jest/no-disabled-tests": "warn",
"jest/no-focused-tests": "error",
"jest/no-identical-title": "error",
"jest/prefer-to-have-length": "warn",
"jest/valid-expect": "error"
}
}
This should fix issues including:
- spc m g g , or g d
- javascript lint error checking
- autocomplete
Learned js2-include-node-externs from here
Learned auto-complete and go-to-definition across files from here
You can find my .spacemacs file here