Created
July 30, 2013 19:45
-
-
Save peterflynn/6116248 to your computer and use it in GitHub Desktop.
Example of writing a CSSLint extension using the new Brackets linting API (https://github.com/adobe/brackets/pull/4588)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | |
/*global define, brackets, $, CSSLint */ | |
define(function (require, exports, module) { | |
"use strict"; | |
// Brackets modules | |
var Linting = brackets.getModule("language/Linting"); | |
// Load CSSLint library | |
require("csslint/csslint"); | |
function cssLinter(text, fullPath) { | |
var results = CSSLint.verify(text); | |
if (!results.messages.length) { | |
return null; // no warnings - passing 100% | |
} | |
// Convert list of warnings to the API's required format | |
var errors = results.messages.map(function (csslintError) { | |
return { | |
pos: { line: csslintError.line - 1, ch: csslintError.col - 1 }, | |
message: csslintError.message, | |
type: csslintError.type === "error" ? Linting.Type.ERROR : Linting.Type.WARNING | |
}; | |
}); | |
return { errors: errors }; | |
} | |
Linting.registerLinter("css", { | |
name: "CSSLint", | |
scanFile: cssLinter | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment