├── .gitignore ├── screenshot └── screenshot.gif ├── CHANGELOG.md ├── README.md ├── package.json ├── styles └── atom-fecs.less ├── LICENSE.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | test 5 | -------------------------------------------------------------------------------- /screenshot/screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/8427003/atom-fecs/HEAD/screenshot/screenshot.gif -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.4 - Release 2 | * recovery less 3 | 4 | ## 0.1.3 - Release 5 | * remove less temporarily 6 | 7 | ## 0.1.1 - Release 8 | * change reporter to 'baidu' 9 | 10 | ## 0.1.0 - Release 11 | * add show diff style as the severity 12 | 13 | ## 0.0.6 - Release 14 | * Every bug fixed 15 | 16 | ## 0.0.5 - First Release 17 | * Every feature added 18 | * Every bug fixed 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # atom-fecs 2 | 3 | ## [baidu fecs](https://github.com/ecomfe/fecs) 代码检查atom插件 4 | 5 | ## 安装 6 | Search for and install `atom-fecs` or `fecs` in Atom's Settings view. 7 | 8 | ## 使用 9 | 当文件打开,或者保存时会自动检查代码 10 | 11 | ## 功能 12 | * 目前只支持 js,css,html,less, sass 文件检查 13 | * 暂不支持代码格式化功能 14 | 15 | ![A screenshot of your package](https://raw.githubusercontent.com/8427003/atom-fecs/master/screenshot/screenshot.gif) 16 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "atom-fecs", 3 | "version": "0.2.2", 4 | "description": "baidu fecs", 5 | "keywords": [ 6 | "atom-fecs", 7 | "baidu-fecs", 8 | "fecs", 9 | "baidu fecs", 10 | "baidu.com", 11 | "eslint", 12 | "jslint", 13 | "js" 14 | ], 15 | "repository": "https://github.com/8427003/atom-fecs", 16 | "license": "MIT", 17 | "engines": { 18 | "atom": ">=1.0.0 <2.0.0" 19 | }, 20 | "consumedServices": { 21 | "status-bar": { 22 | "versions": { 23 | "^1.0.0": "consumeStatusBar" 24 | } 25 | } 26 | }, 27 | "dependencies": { 28 | "fecs": "*", 29 | "eslint-plugin-flowtype": "*" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /styles/atom-fecs.less: -------------------------------------------------------------------------------- 1 | @import 'ui-variables.less'; 2 | 3 | atom-text-editor.editor { 4 | 5 | .fecs-line-error { 6 | background-color: fade(@background-color-error, 20%); 7 | } 8 | 9 | .fecs-line-warning { 10 | background-color: fade(@background-color-warning, 20%); 11 | } 12 | 13 | .fecs-errors { 14 | text-align: left; 15 | } 16 | 17 | .gutter { 18 | .fecs-line-number-error { 19 | color: @text-color-error !important; 20 | opacity: 1; 21 | &:hover { 22 | background-color: @background-color-highlight; 23 | } 24 | } 25 | .fecs-line-number-warning { 26 | color: @text-color-warning !important; 27 | opacity: 1; 28 | &:hover { 29 | background-color: @background-color-highlight; 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author email:8427003@qq.com 百度hi:雷锋with红领巾 3 | * @file baidu fecs 代码检查插件; 4 | */ 5 | 6 | /* globals atom */ 7 | 8 | const fecs = require('fecs'); 9 | const Atom = require('atom'); 10 | const path = require('path'); 11 | 12 | let disposables = null; 13 | let mainDisposables = null; 14 | let editor = null; 15 | let errorsMap = {}; 16 | 17 | let SEVERITY = { 18 | ERROR: 2, 19 | WARNING: 1 20 | }; 21 | 22 | let decorConfig = { 23 | lineWarning: { 24 | 'type': 'line', 25 | 'class': 'fecs-line-warning' 26 | }, 27 | lineError: { 28 | 'type': 'line', 29 | 'class': 'fecs-line-error' 30 | }, 31 | lineNumWarning: { 32 | 'type': 'line-number', 33 | 'class': 'fecs-line-number-warning' 34 | }, 35 | lineNumError: { 36 | 'type': 'line-number', 37 | 'class': 'fecs-line-number-error' 38 | } 39 | }; 40 | 41 | /* eslint-disable fecs-valid-map-set */ 42 | let checkExtMap = { 43 | '.js': 1, 44 | '.html': 1, 45 | '.css': 1, 46 | '.less': 1, 47 | '.sass': 1 48 | }; 49 | /* eslint-enable fecs-valid-map-set */ 50 | 51 | 52 | function addDecorators(errors) { 53 | 54 | errorsMap = {}; 55 | 56 | for (let i = 0, size = errors.length; i < size; i++) { 57 | 58 | let item = errors[i]; 59 | let {line, severity} = item; 60 | let marker = editor.markBufferRange([[line - 1, 1], [line - 1, 1]]); 61 | 62 | if (severity === SEVERITY.WARNING) { 63 | editor.decorateMarker(marker, decorConfig.lineWarning); 64 | editor.decorateMarker(marker, decorConfig.lineNumWarning); 65 | } 66 | else { 67 | editor.decorateMarker(marker, decorConfig.lineError); 68 | editor.decorateMarker(marker, decorConfig.lineNumError); 69 | } 70 | 71 | errorsMap[line] = item; 72 | 73 | } 74 | 75 | } 76 | 77 | function clearAllDecorators() { 78 | 79 | Object 80 | .keys(decorConfig) 81 | .forEach(key => 82 | editor 83 | .getDecorations(decorConfig[key]) 84 | .forEach(decorator => decorator.destroy()) 85 | ); 86 | 87 | } 88 | 89 | function check() { 90 | fecs.check(getOptions(), (success, errors = []) => { 91 | clearAllDecorators(); 92 | if (errors && errors[0]) { 93 | addDecorators(errors[0].errors); 94 | } 95 | updateStatusBar(); 96 | }); 97 | } 98 | 99 | function getOptions() { 100 | return Object.assign( 101 | {}, 102 | fecs.getOptions(), 103 | { 104 | /* eslint-disable */ 105 | _: [ 106 | getPath() 107 | ], 108 | /* eslint-enable */ 109 | reporter: 'baidu' 110 | } 111 | ); 112 | } 113 | function getPath() { 114 | return editor && editor.getPath(); 115 | } 116 | 117 | let fecsStatusBar = (function () { 118 | 119 | let element = document.createElement('a'); 120 | element.setAttribute('id', 'fecs-statusbar'); 121 | return element; 122 | 123 | })(); 124 | 125 | function updateStatusBar() { 126 | 127 | if (!editor) { 128 | return; 129 | } 130 | 131 | let line = editor.getCursorBufferPosition().row + 1; 132 | let item = errorsMap && errorsMap[line]; 133 | let text = ''; 134 | 135 | if (item) { 136 | 137 | let { 138 | line, 139 | column, 140 | rule, 141 | message 142 | } = item; 143 | 144 | text = `fecs: ${line}:${column} ${message} [${rule}]`; 145 | } 146 | 147 | fecsStatusBar.textContent = text; 148 | fecsStatusBar.setAttribute('title', text); 149 | } 150 | 151 | function registerEvents() { 152 | editor = atom.workspace.getActiveTextEditor(); 153 | if (!editor) { 154 | return; 155 | } 156 | 157 | let filePath = getPath(); 158 | if (!filePath) { 159 | return; 160 | } 161 | 162 | let ext = path.extname(filePath); 163 | 164 | if (!checkExtMap[ext]) { 165 | return; 166 | } 167 | disposables && disposables.dispose(); 168 | disposables = new Atom.CompositeDisposable(); 169 | disposables.add(editor.onDidSave(check)); 170 | disposables.add(editor.onDidChangeCursorPosition(updateStatusBar)); 171 | check(); 172 | } 173 | 174 | module.exports = { 175 | activate() { 176 | mainDisposables = new Atom.CompositeDisposable(); 177 | mainDisposables.add(atom.workspace.observeActivePaneItem(registerEvents)); 178 | }, 179 | consumeStatusBar(statusBar) { 180 | statusBar.addLeftTile({item: fecsStatusBar}); 181 | }, 182 | deactivate() { 183 | disposables && disposables.dispose(); 184 | mainDisposables && mainDisposables.dispose(); 185 | mainDisposables = disposables = editor = null; 186 | } 187 | 188 | }; 189 | --------------------------------------------------------------------------------