├── README.md ├── csslint ├── LICENSE └── csslint.js ├── main.js └── package.json /README.md: -------------------------------------------------------------------------------- 1 | brackets-csslint 2 | ================= 3 | 4 | A Brackets extension to enable CSSLint support. To install, place in your ```brackets/src/extensions/user``` folder. 5 | 6 | CSSLint makes use of Bracket's built-in linting system. Errors will be signified 7 | with a yellow warning icon in the lower right hand corner of the editor. Clicking 8 | it will open a list of issues for the current file. If there are no issues, a green 9 | icon will be displayed instead. 10 | 11 | Global default options are available under "Debug > Open Preferences File" by adding or modifying "csslint.options". 12 | 13 | CSSLint also supports .csslintrc files. See this for more information: https://github.com/CSSLint/csslint/issues/359 14 | 15 | Issues/Updates 16 | ===== 17 | 18 | [11/10/2017] Merge PR - https://github.com/cfjedimaster/brackets-csslint/pull/46 19 | 20 | [6/30/2015] Merge PR - https://github.com/cfjedimaster/brackets-csslint/pull/43 21 | 22 | [5/27/2015] Adding support for global preferences 23 | 24 | [1/22/2015] Fix for CSSLint behaving badly. 25 | 26 | [1/4/2015] Updated CSSLint - again - this time credit goes to @ArgTang 27 | 28 | [1/4/2015] Updated CSSLint 29 | 30 | [7/13/2014] Remove SCSS support, as I thought I'd need to. 31 | 32 | [1/26/2014] User globexdesigns added support for .csslintrc files. 33 | 34 | [11/29/2013] Updated the display to include both the name of the rule, which makes it a bit clearer I think, as well as the code for the rule. 35 | 36 | [10/15/2013] So - the main CSSLint lib I used totally screwed up Brackets by messing up the exports module. I did 37 | some guess work and - I think it's kosher now. 38 | 39 | [10/8/2013] Two things. One - sometimes CSSLint returned a "document" level warning. Brackets Lint API doesn't 40 | support this, so for now, we skip it. 41 | 42 | Two - SCSS support is in, but I'm fairly certain it isn't working right. I'll probably remove it. 43 | 44 | Third - updated CSSLint to latest. 45 | 46 | [10/8/2013] Small mod to fix a loading issue with linting (temp) 47 | 48 | [9/23/2013] New linting API used for Sprint 31. 49 | 50 | [6/30/2013] Merged in a fix by Daniel Seymour. 51 | 52 | [6/22/2013] Merged in an updated CSSLint by John Lafitte. 53 | 54 | [6/7/2013] Updated package.json version for fixes by Daniel Seymour. 55 | 56 | [6/5/2013] Fixed a bunch of JSLint errors in csslint.js. 57 | 58 | [6/2/2013] Ugh, had the wrong package.json stuff in. Stupid Ray. Also updated code to use 59 | PanelManager. 60 | 61 | [6/2/2013] Makes csslint work like my jshint extension and auto hide/show on .css files. 62 | 63 | [5/24/2013] Added package.json support 64 | 65 | [4/16/2013] Tweak to menu add function. 66 | 67 | [12/4/2012] Updated to remove preferences code (not needed) and fix a word wrap issue. Thanks again to Randy Edmunds and Chema Balsas. 68 | 69 | [11/29/2012] Updated display code to fix a few issues with resizing. It also remembers the height now and makes use of Mustache. A HUGE 70 | thanks, again, to Randy Edmunds. I stole I mean borrowed a lot of code from his shortcut (https://github.com/redmunds/brackets-display-shortcuts). 71 | 72 | Also updated CSSLint to the latest version. 73 | 74 | [11/12/2012] Update code to properly insert the content over the status bar. Also made it resizable. 75 | 76 | [9/26/2012] Escape HTML in the message. Fix width issue. Thanks to Randy Edmunds for the reports. 77 | 78 | Per feedback from Narciso Jaramillo, I use a checkbox to show enabled/disabled status and move to the item when you click a row. 79 | 80 | Credit 81 | ===== 82 | Built with [CSSLint](http://csslint.net/) and heavily based on the work of [Jonathan Rowny](http://www.jonathanrowny.com/). 83 | -------------------------------------------------------------------------------- /csslint/LICENSE: -------------------------------------------------------------------------------- 1 | CSSLint 2 | Copyright (c) 2011 Nicole Sullivan and Nicholas C. Zakas. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | /*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ 2 | /*global define, brackets, $, CSSLint */ 3 | 4 | define(function (require, exports, module) { 5 | "use strict"; 6 | 7 | var DocumentManager = brackets.getModule("document/DocumentManager"), 8 | FileSystem = brackets.getModule("filesystem/FileSystem"), 9 | CodeInspection = brackets.getModule("language/CodeInspection"), 10 | LanguageManager = brackets.getModule("language/LanguageManager"), 11 | PreferencesManager = brackets.getModule("preferences/PreferencesManager"), 12 | ProjectManager = brackets.getModule("project/ProjectManager"), 13 | AppInit = brackets.getModule("utils/AppInit"); 14 | 15 | var pm = PreferencesManager.getExtensionPrefs("csslint"), 16 | defaults; 17 | 18 | pm.definePreference("options", "object", {}) 19 | .on("change", function () { 20 | defaults = pm.get("options"); 21 | }); 22 | 23 | defaults = pm.get("options"); 24 | 25 | require("csslint/csslint"); 26 | 27 | var _configFileName = ".csslintrc", 28 | config = {}; 29 | 30 | function cssLinter(text) { 31 | var results; 32 | 33 | // Merge default CSSLint ruleset with the custom .csslintrc config 34 | var ruleset = $.extend(CSSLint.getRuleset(), defaults, config.options); 35 | 36 | // Execute CSSLint 37 | results = CSSLint.verify(text, ruleset); 38 | 39 | if (results.messages.length) { 40 | var result = { 41 | errors: [] 42 | }; 43 | 44 | for (var i = 0, len = results.messages.length; i < len; i++) { 45 | 46 | /* 47 | Currently the Brackets Lint API doesn't work with warnings that are 'document' level. 48 | See bug: https://github.com/adobe/brackets/issues/5452 49 | */ 50 | var messageOb = results.messages[i]; 51 | 52 | if (!messageOb.line) continue; 53 | //default 54 | var type = CodeInspection.Type.WARNING; 55 | 56 | if (messageOb.type === "error") { 57 | type = CodeInspection.Type.ERROR; 58 | } else if (messageOb.type === "warning") { 59 | type = CodeInspection.Type.WARNING; 60 | } 61 | 62 | var message = messageOb.rule.name + " - " + messageOb.message; 63 | message += " (" + messageOb.rule.id + ")"; 64 | 65 | result.errors.push({ 66 | pos: { 67 | line: messageOb.line - 1, 68 | ch: messageOb.col 69 | }, 70 | message: message, 71 | 72 | type: type 73 | }); 74 | } 75 | 76 | return result; 77 | } else { 78 | //no errors 79 | return null; 80 | } 81 | 82 | } 83 | 84 | 85 | /** 86 | * Loads project-wide CSSLint configuration. 87 | * 88 | * CSSLint project file should be located at /.csslintrc. It 89 | * is loaded each time project is changed or the configuration file is 90 | * modified. 91 | * 92 | * @return Promise to return CSSLint configuration object. 93 | * 94 | */ 95 | function _loadProjectConfig() { 96 | 97 | var projectRootEntry = ProjectManager.getProjectRoot(), 98 | result = new $.Deferred(), 99 | file, 100 | config; 101 | 102 | file = FileSystem.getFileForPath(projectRootEntry.fullPath + _configFileName); 103 | file.read(function (err, content) { 104 | if (!err) { 105 | var cfg = {}; 106 | try { 107 | config = JSON.parse(content); 108 | } catch (e) { 109 | console.error("CSSLint: Error parsing " + file.fullPath + ". Details: " + e); 110 | result.reject(e); 111 | return; 112 | } 113 | cfg.options = config; 114 | result.resolve(cfg); 115 | } else { 116 | result.reject(err); 117 | } 118 | }); 119 | return result.promise(); 120 | } 121 | 122 | /** 123 | * Attempts to load project configuration file. 124 | */ 125 | function tryLoadConfig() { 126 | /** 127 | * Makes sure CSSLint is re-ran when the config is reloaded 128 | * 129 | * This is a workaround due to some loading issues in Sprint 31. 130 | * See bug for details: https://github.com/adobe/brackets/issues/5442 131 | */ 132 | function _refreshCodeInspection() { 133 | CodeInspection.toggleEnabled(); 134 | CodeInspection.toggleEnabled(); 135 | } 136 | _loadProjectConfig() 137 | .done(function (newConfig) { 138 | config = newConfig; 139 | }) 140 | .fail(function () { 141 | config = {}; 142 | }) 143 | .always(function () { 144 | _refreshCodeInspection(); 145 | }); 146 | } 147 | 148 | AppInit.appReady(function () { 149 | 150 | LanguageManager.getLanguage("json").addFileName(_configFileName); 151 | 152 | CodeInspection.register("css", { 153 | name: "CSSLint", 154 | scanFile: cssLinter 155 | }); 156 | 157 | DocumentManager 158 | .on("documentSaved.csslint documentRefreshed.csslint", function (e, document) { 159 | // if this project's .csslintrc config has been updated, reload 160 | if (document.file.fullPath === ProjectManager.getProjectRoot().fullPath + _configFileName) { 161 | tryLoadConfig(); 162 | } 163 | }); 164 | 165 | ProjectManager 166 | .on("projectOpen.csslint", function () { 167 | tryLoadConfig(); 168 | }); 169 | 170 | tryLoadConfig(); 171 | 172 | }); 173 | }); 174 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "camden.csslint", 3 | "title": "CSSLint", 4 | "description": "Adds CSSLint support to Brackets.", 5 | "homepage": "https://github.com/cfjedimaster/brackets-csslint", 6 | "version": "2.0.22", 7 | "author": "Raymond Camden (http://www.raymondcamden.com)", 8 | "license": "MIT", 9 | "engines": { 10 | "brackets": ">=0.31.0" 11 | } 12 | } 13 | --------------------------------------------------------------------------------