Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
// Format style blocks
for (let i = 0; i < vueComponent.styles.length; i++) {
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);
formatted = insertContent(formatted, block, formattedJs);
if (formattedJs.trim() !== js.trim()) {
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 });
ejs.renderFile(filepath, data, options, (err, str) => {
if (err) return observer.error(err);
let messages = lint.format(lint.verify(str, options.rules), {colors: true});
if (messages.length > 0) {
console.log(chalk.yellow.bold('\nHTML WARNING'));
}
messages.forEach((message) => {
console.log(message);
});
fs.outputFile(outputPath, str, options, (err) => {
if (err) return observer.error(err);
observer.next(outputPath);
});
});
});
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 ++;
}
}
});