以下由sublime使用教學欄位來介紹如何在sublime中實現程式碼偵測,希望對需要的朋友有幫助!
在sublime中設定linter, eslint
sublime外掛程式安裝
打開pci,安裝sublimeLinter
進入到,對path進行設定:
● 設定node的基本位置:/usr/local/bin/node, /usr/local/bin
● 配置node_modules的基本位置:/usr/local/lib/node_modules
● 配置其他各項插件的位置:如eslint: /usr/local/bin/eslint
範例程式碼如下:
"paths": { "linux": [], "osx": [ "/usr/local/bin/node", "/usr/local/lib/node_modules", "/usr/local/bin/eslint", "/usr/local/bin/jslint" ], "windows": [] }
安裝外掛程式(以eslint為例):
安裝eslint的npm插件,包含:
● sudo npm i eslint babel-eslint -g
● 將所安裝的工具的路徑放到的path中,即:/usr/local/bin/eslint
● 在專案中設定.eslintrc文件,類似:(每個項目都需要設定)
● 當中包含非常多的依賴,可以在專案中輸入eslint .,然後根據提示對缺少的依賴進行sudo npm i -g ***
然後就可以愉快的使用啦!
可以透過右鍵進入到sublimelinter來呼叫其功能。
.eslintrc檔案範例
{ "env": { "browser": true, "node": true, "es6": true }, "parser": "babel-eslint", "extends" : [ "airbnb" ], "plugins": [ "babel", "promise" ], "ecmaFeatures": { "jsx": true }, "rules": { "semi": [2, "always"], "quotes": [2, "single"] } }
最後
展示設定完成後的sublimelinter-user.settings:
{ "user": { "debug": true, "delay": 0.25, "error_color": "D02000", "gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme", "gutter_theme_excludes": [], "lint_mode": "background", "linters": { "eslint": { "@disable": false, "args": [], "ecmaFeatures": { "jsx": true }, "env": { "browser": true, "es6": true, "node": true }, "excludes": [], "extends": [ "standard" ], "parser": "babel-eslint", "plugins": [ "babel", "promise" ], "rules": { "quotes": [ 2, "single" ], "semi": [ 2, "always" ] } }, "jsxhint": { "@disable": false, "args": [], "excludes": [] } }, "mark_style": "stippled underline", "no_column_highlights_line": false, "passive_warnings": false, "paths": { "linux": [], "osx": [ "/usr/local/bin/node", "/usr/local/lib/node_modules", "/usr/local/bin/eslint" ], "windows": [] }, "python_paths": { "linux": [], "osx": [], "windows": [] }, "rc_search_limit": 3, "shell_timeout": 10, "show_errors_on_save": false, "show_marks_in_minimap": true, "syntax_map": { "html (django)": "html", "html (rails)": "html", "html 5": "html", "javascript (babel)": "javascript", "magicpython": "python", "php": "html", "python django": "python", "pythonimproved": "python" }, "warning_color": "DDB700", "wrap_find": true } }
以上是在sublime中實現程式碼檢測的詳細內容。更多資訊請關注PHP中文網其他相關文章!