Clean up modified css-lint
This commit is contained in:
parent
5bfbab62d7
commit
91825d11fd
186
vendor-overwrites/codemirror/addon/lint/css-lint.js
vendored
186
vendor-overwrites/codemirror/addon/lint/css-lint.js
vendored
|
@ -3,100 +3,112 @@
|
||||||
|
|
||||||
// Depends on csslint.js from https://github.com/stubbornella/csslint
|
// Depends on csslint.js from https://github.com/stubbornella/csslint
|
||||||
|
|
||||||
// declare global: CSSLint
|
/* global CodeMirror require define */
|
||||||
|
/* global CSSLint stylelint stylelintDefaultConfig */
|
||||||
|
'use strict';
|
||||||
|
|
||||||
(function(mod) {
|
(mod => {
|
||||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
if (typeof exports === 'object' && typeof module === 'object') {
|
||||||
mod(require("../../lib/codemirror"));
|
// CommonJS
|
||||||
else if (typeof define == "function" && define.amd) // AMD
|
mod(require('../../lib/codemirror'));
|
||||||
define(["../../lib/codemirror"], mod);
|
} else if (typeof define === 'function' && define.amd) {
|
||||||
else // Plain browser env
|
// AMD
|
||||||
|
define(['../../lib/codemirror'], mod);
|
||||||
|
} else {
|
||||||
|
// Plain browser env
|
||||||
mod(CodeMirror);
|
mod(CodeMirror);
|
||||||
})(function(CodeMirror) {
|
}
|
||||||
"use strict";
|
})(CodeMirror => {
|
||||||
|
CodeMirror.registerHelper('lint', 'csslint', text => {
|
||||||
CodeMirror.registerHelper("lint", "csslint", function(text) {
|
const found = [];
|
||||||
let found = [];
|
if (window.CSSLint) {
|
||||||
if (window.CSSLint) {
|
/* STYLISH: hack start (part 1) */
|
||||||
|
const rules = CSSLint.getRules();
|
||||||
/* STYLISH: hack start (part 1) */
|
const allowedRules = [
|
||||||
var rules = CSSLint.getRules();
|
'display-property-grouping',
|
||||||
var allowedRules = ["display-property-grouping", "duplicate-properties", "empty-rules", "errors", "known-properties"];
|
'duplicate-properties',
|
||||||
CSSLint.clearRules();
|
'empty-rules',
|
||||||
rules.forEach(function(rule) {
|
'errors',
|
||||||
if (allowedRules.indexOf(rule.id) >= 0) {
|
'known-properties'
|
||||||
CSSLint.addRule(rule);
|
];
|
||||||
}
|
CSSLint.clearRules();
|
||||||
});
|
rules.forEach(rule => {
|
||||||
/* STYLISH: hack end */
|
if (allowedRules.indexOf(rule.id) >= 0) {
|
||||||
|
CSSLint.addRule(rule);
|
||||||
var results = CSSLint.verify(text), messages = results.messages, message = null;
|
|
||||||
for ( var i = 0; i < messages.length; i++) {
|
|
||||||
message = messages[i];
|
|
||||||
|
|
||||||
/* STYLISH: hack start (part 2) */
|
|
||||||
if (message.type === 'warning') {
|
|
||||||
// @font-face {font-family: 'Ampersand'; unicode-range: U+26;}
|
|
||||||
if (message.message.indexOf('unicode-range') !== -1) {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
else if ( // color: hsl(210, 100%, 2.2%); or color: hsla(210, 100%, 2.2%, 0.3);
|
});
|
||||||
message.message.startsWith('Expected (<color>) but found \'hsl') &&
|
|
||||||
/hsla?\(\s*(-?\d+)%?\s*,\s*(-?\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%(\s*,\s*(-?\d+|-?\d*.\d+))?\s*\)/.test(message.message)
|
|
||||||
) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
//
|
|
||||||
}
|
|
||||||
/* STYLISH: hack end */
|
/* STYLISH: hack end */
|
||||||
|
|
||||||
var startLine = message.line -1, endLine = message.line -1, startCol = message.col -1, endCol = message.col;
|
const results = CSSLint.verify(text);
|
||||||
found.push({
|
const messages = results.messages;
|
||||||
from: CodeMirror.Pos(startLine, startCol),
|
const hslRegex = /hsla?\(\s*(-?\d+)%?\s*,\s*(-?\d+)%\s*,\s*(-?\d+|-?\d*.\d+)%(\s*,\s*(-?\d+|-?\d*.\d+))?\s*\)/;
|
||||||
to: CodeMirror.Pos(endLine, endCol),
|
let message = null;
|
||||||
message: message.message,
|
for (let i = 0; i < messages.length; i++) {
|
||||||
severity : message.type
|
message = messages[i];
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return found;
|
|
||||||
});
|
|
||||||
|
|
||||||
CodeMirror.registerHelper("lint", "stylelint", function(text) {
|
/* STYLISH: hack start (part 2) */
|
||||||
let found = [];
|
if (message.type === 'warning') {
|
||||||
window.stylelint = require('stylelint').lint;
|
// @font-face {font-family: 'Ampersand'; unicode-range: U+26;}
|
||||||
if (window.stylelint) {
|
if (message.message.indexOf('unicode-range') !== -1) {
|
||||||
return BG.chromeLocal.getValue('editorStylelintRules').then((rules = stylelintDefaultConfig.rules) => {
|
continue;
|
||||||
// stylelintDefaultConfig stored in stylelint-config.js & loaded by edit.html
|
} else if (
|
||||||
if (Object.keys(rules).length === 0) {
|
// color: hsl(210, 100%, 2.2%); or color: hsla(210, 100%, 2.2%, 0.3);
|
||||||
rules = stylelintDefaultConfig.rules;
|
message.message.startsWith('Expected (<color>) but found \'hsl') &&
|
||||||
}
|
hslRegex.test(message.message)
|
||||||
return stylelint({
|
) {
|
||||||
code: text,
|
continue;
|
||||||
config: {
|
|
||||||
syntax: stylelintDefaultConfig.syntax,
|
|
||||||
rules: rules
|
|
||||||
}
|
|
||||||
}).then(output => {
|
|
||||||
const warnings = output.results.length ? output.results[0].warnings : [],
|
|
||||||
len = warnings.length;
|
|
||||||
let i, warning;
|
|
||||||
if (len) {
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
warning = warnings[i];
|
|
||||||
found.push({
|
|
||||||
from: CodeMirror.Pos(warning.line - 1, warning.column - 1),
|
|
||||||
to: CodeMirror.Pos(warning.line - 1, warning.column),
|
|
||||||
message: warning.text,
|
|
||||||
severity : warning.severity
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
/* STYLISH: hack end */
|
||||||
});
|
const startLine = message.line - 1;
|
||||||
});
|
const endLine = message.line - 1;
|
||||||
}
|
const startCol = message.col - 1;
|
||||||
return found;
|
const endCol = message.col;
|
||||||
});
|
found.push({
|
||||||
|
from: CodeMirror.Pos(startLine, startCol),
|
||||||
|
to: CodeMirror.Pos(endLine, endCol),
|
||||||
|
message: message.message,
|
||||||
|
severity : message.type
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
});
|
||||||
|
|
||||||
|
CodeMirror.registerHelper('lint', 'stylelint', text => {
|
||||||
|
const found = [];
|
||||||
|
window.stylelint = require('stylelint').lint;
|
||||||
|
if (window.stylelint) {
|
||||||
|
return BG.chromeLocal.getValue('editorStylelintRules').then((rules = stylelintDefaultConfig.rules) => {
|
||||||
|
// stylelintDefaultConfig stored in stylelint-config.js & loaded by edit.html
|
||||||
|
if (Object.keys(rules).length === 0) {
|
||||||
|
rules = stylelintDefaultConfig.rules;
|
||||||
|
}
|
||||||
|
return stylelint({
|
||||||
|
code: text,
|
||||||
|
config: {
|
||||||
|
syntax: stylelintDefaultConfig.syntax,
|
||||||
|
rules: rules
|
||||||
|
}
|
||||||
|
}).then(output => {
|
||||||
|
const warnings = output.results.length ? output.results[0].warnings : [];
|
||||||
|
const len = warnings.length;
|
||||||
|
let warning;
|
||||||
|
if (len) {
|
||||||
|
for (let i = 0; i < len; i++) {
|
||||||
|
warning = warnings[i];
|
||||||
|
found.push({
|
||||||
|
from: CodeMirror.Pos(warning.line - 1, warning.column - 1),
|
||||||
|
to: CodeMirror.Pos(warning.line - 1, warning.column),
|
||||||
|
message: warning.text,
|
||||||
|
severity : warning.severity
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return found;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user