storj/web/eslint-storj/index.js
Egon Elbre e5977ec849 web/: add custom linter for requiring @vue/component
Also ignore coverage folder for linting. I had to add a new
.stylelintignore file, because ignoreFiles property was not properly
working.

Change-Id: Iadd99b64eadd9c4103f750519263113ae8780ce1
2021-09-01 13:56:37 +00:00

46 lines
1.8 KiB
JavaScript

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
module.exports = {
rules: {
"vue/require-annotation": {
meta: {
fixable: "code",
},
create: function(context) {
return {
Decorator(node) {
let isComponent = false;
const expr = node.expression;
if(expr.name === "Component"){
isComponent = true;
} else if (expr.callee && expr.callee.name === "Component"){
isComponent = true;
}
if(!isComponent){ return; }
const commentsBefore = context.getCommentsBefore(node);
const decoratorLine = node.loc.start.line;
let annotated = false;
commentsBefore.forEach(comment => {
if(comment.loc.start.line === decoratorLine - 1){
if(comment.value.trim() === "@vue/component") {
annotated = true;
}
}
})
if(!annotated){
context.report({
node: node,
message: '@Component requires // @vue/component',
fix: function(fixer) {
return fixer.insertTextBefore(node, "// @vue/component\n");
}
});
}
}
};
}
}
}
};