Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Raw JS or SCSS file
if (file.endsWith('.js')) {
options.parser = 'babylon';
formatted = prettier.format(source, options);
if (formatted !== source) {
notSoPretty = true;
}
formatted = eslint(formatted);
} else if (file.endsWith('.scss')) {
formatted = lintScss(source);
} else if (file.endsWith('.vue')) {
let block;
// First lint the whole vue component with eslint
formatted = eslint(source);
// Now run htmlhint on the whole vue component
let htmlMessages = HTMLHint.verify(formatted, htmlHintConfig);
if (htmlMessages.length) {
messages.push(...HTMLHint.format(htmlMessages, { colors: true }));
}
let vueComponent = compiler.parseComponent(formatted);
// Prettier strips the 2 space indentation that we enforce within script tags for vue
// components. So here we account for those 2 spaces that will be added.
options.printWidth = options.printWidth - 2;
// Format script block
if (vueComponent.script) {
block = vueComponent.script;
const js = block.content;
options.parser = 'babylon';
let formattedJs = prettier.format(js, options);
var finish = function (target, response, cb) {
var messages = [],
empty = typeof response === 'undefined' || response === '';
// Lint generated html and check if response is empty
if (options.htmlhint !== false) {
messages = HTMLHint.verify(response || '', options.htmlhint);
}
// move on to the next file if everything went right
if (!error && messages.length === 0 && !empty) {
grunt.file.write(target, response);
grunt.log.ok();
grunt.log.debug(target + ' written');
compiled.push(target);
// there was an error, show messages to the user if applicable and move on
} else {
grunt.log.error();
if (empty) {
grunt.log.warn('Resulting HTML is empty');
}
return through2.obj((file, enc, cb) => {
const report = HTMLHint.verify(file.contents.toString(), ruleset);
// Send status down-stream
file.htmlhint = formatOutput(report, file, options);
cb(null, file);
});
};
formatted = eslint(source);
let vueComponent = compiler.parseComponent(formatted);
// Format template block
if (vueComponent.template && vueComponent.template.content) {
formatted = insertContent(
formatted,
vueComponent.template,
vueComponent.template.content
);
vueComponent = compiler.parseComponent(formatted);
}
// Now run htmlhint on the whole vue component
let htmlMessages = HTMLHint.verify(formatted, htmlHintConfig);
if (htmlMessages.length) {
messages.push(...HTMLHint.format(htmlMessages, { colors: true }));
}
// Format script block
if (vueComponent.script) {
block = vueComponent.script;
const js = block.content;
let formattedJs = prettierFormat(js, 'babel', true);
formatted = insertContent(formatted, block, formattedJs);
if (formattedJs.trim() !== js.trim()) {
notSoPretty = true;
}
}
const htmlHintRules: RuleSet = {
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"doctype-first": true,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"attr-no-duplication": true,
"title-require": true,
"space-tab-mixed-disabled": "tab"
};
const result = HTMLHint.verify('<span></span>', htmlHintRules);
const formatted = HTMLHint.format(result, { indent: 2 });
async function lintFile(filePath: string, configData: RuleSet): Promise {
logger.debug(lintFile.name, `filePath: ${filePath}`);
return {
result: HTMLHint.verify(await fileSystem.readFileAsync(filePath), configData),
filePath
};
}
arrFilesSrc.forEach(function(filepath) {
var file = grunt.file.read(filepath),
msg = " " + filepath,
messages;
if (file.length) {
messages = HTMLHint.verify(file, options);
if (messages.length > 0) {
grunt.log.writeln(msg);
var arrLogs = HTMLHint.format(messages, {
colors: true,
indent: 6
});
arrLogs.forEach(function(log){
grunt.log.writeln(log);
});
grunt.log.writeln('');
hintCount += messages.length;
fileCount ++;
}
}
});
.then((contents) => ({
filePath: file,
report: HTMLHint.verify(contents, this.ingredientConfig),
}))
)