Skip to content

Commit

Permalink
Added v1 of the extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
slai committed Sep 27, 2014
1 parent 22482cb commit 7411f81
Show file tree
Hide file tree
Showing 4 changed files with 3,583 additions and 0 deletions.
55 changes: 55 additions & 0 deletions main.js
@@ -0,0 +1,55 @@
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
/*global define, brackets, $, window, yaml, Mustache */
define(function (require, exports, module) {
'use strict';
var AppInit = brackets.getModule("utils/AppInit"),
CodeInspection = brackets.getModule("language/CodeInspection");
var yaml = require("js-yaml");

function buildLinterErrorObject(ex, type) {
var o = {
pos: {line: ex.mark.line, ch: ex.mark.column},
type: type
};
var message = ex.toString();
if (message.indexOf('JS-YAML: ') === 0) {
message = message.substring('JS-YAML: '.length);
}
o.message = message;

return o;
}

function yamlLinter(text, fullPath) {
var warnings = [];
var error = null;
var i = 0;

try {
yaml.safeLoad(text, {
'onWarning': function (w) { warnings.push(w); }
});
} catch (e) {
error = e;
}

var result = { errors: [] };
if (warnings) {
for (i = 0; i < warnings.length; i++) {
result.errors.push(buildLinterErrorObject(warnings[i], CodeInspection.Type.WARNING));
}
}
if (error) {
result.errors.push(buildLinterErrorObject(error, CodeInspection.Type.ERROR));
}

if (result.errors) {
return result;
}
else {
return null;
}
}

AppInit.appReady(function () { CodeInspection.register("yaml", { name: "YamlLint", scanFile: yamlLinter }); });
});
19 changes: 19 additions & 0 deletions package.json
@@ -0,0 +1,19 @@
{
"name": "brackets-yaml-linter",
"title": "YAML Linter",
"version": "1.0.0",
"description": "Provides linting functionality for YAML files",
"homepage": "https://github.com/slai/brackets-yaml-linter",
"author": "Samuel Lai <sam@edgylogic.com>",
"license": "MIT",
"categories": "editing",
"keywords": [
"yaml",
"lint",
"coding",
"editing"
],
"engines": {
"brackets": ">=0.38.0"
}
}
5 changes: 5 additions & 0 deletions requirejs-config.json
@@ -0,0 +1,5 @@
{
"paths": {
"js-yaml": "./thirdparty/js-yaml"
}
}

0 comments on commit 7411f81

Please sign in to comment.