-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jairo Suarez
committed
Jul 22, 2023
1 parent
82556f2
commit db6b027
Showing
8 changed files
with
3,128 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.DS_Store | ||
node_modules/ | ||
.env | ||
.nyc_output/ | ||
coverage/ | ||
|
||
# IDE user config | ||
.vscode/ | ||
.idea/ | ||
.neovim/ | ||
.vs/ | ||
|
||
# Logs | ||
yarn-error.log | ||
npm-debug.log | ||
|
||
# Build output | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = { | ||
presets: [ | ||
['@babel/preset-env', { targets: { node: 'current' } }], | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
plugins: [ | ||
'data-tids', | ||
], | ||
rules: { | ||
'data-tids/missing-data-tid': 'error', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
const path = require("path"); | ||
const requireindex = require("requireindex"); | ||
|
||
module.exports = { | ||
meta: { | ||
name: "eslint-plugin-vue-data-tids", | ||
version: require("../package.json").version, | ||
}, | ||
configs: requireindex(path.join(__dirname, "./configs")), | ||
rules: requireindex(path.join(__dirname, "./rules")), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use strict"; | ||
|
||
function kebabToPascalCase(str) { | ||
return str | ||
.replace(/(?:^|[-_])(\w)/g, (c) => c.toUpperCase()) | ||
.replace(/[-_]/g, ""); | ||
} | ||
|
||
const testableTagNames = [ | ||
"Input", | ||
"Button", | ||
"Checkbox", | ||
"Radio", | ||
"Select", | ||
"Textarea", | ||
"Link", | ||
]; | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "Enforce data-tid attribute on all elements", | ||
category: "recommended", | ||
}, | ||
fixable: "code", | ||
schema: [], | ||
messages: { | ||
missingDataTid: "Missing data-tid attribute", | ||
}, | ||
}, | ||
create(context) { | ||
return context.parserServices.defineTemplateBodyVisitor({ | ||
VElement(node) { | ||
const tag = kebabToPascalCase(node.rawName); | ||
const tokens = context.parserServices.getTemplateBodyTokenStore(); | ||
if (testableTagNames.includes(tag)) { | ||
const dataTid = node.startTag.attributes.find( | ||
(attr) => attr.key.name === "data-tid" | ||
); | ||
if (!dataTid) { | ||
context.report({ | ||
node, | ||
loc: tokens.getFirstToken(node).loc, | ||
messageId: "missingDataTid", | ||
fix: (fixer) => | ||
fixer.insertTextAfter( | ||
tokens.getFirstToken(node), | ||
' data-tid=""' | ||
), | ||
}); | ||
} | ||
} | ||
}, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const RuleTester = require("eslint").RuleTester; | ||
|
||
const rule = require("../../src/rules/missing-data-tid"); | ||
|
||
const ruleTester = new RuleTester({ | ||
parser: require.resolve("vue-eslint-parser"), | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: "module", | ||
}, | ||
}); | ||
|
||
ruleTester.run("missing-data-tid", rule, { | ||
valid: ['<template><input data-tid="foo" /></template>'], | ||
invalid: [ | ||
{ | ||
code: "<template><input /></template>", | ||
errors: [ | ||
{ | ||
message: "Missing data-tid attribute", | ||
type: "VElement", | ||
}, | ||
], | ||
output: '<template><input data-tid="" /></template>', | ||
}, | ||
], | ||
}); |
Oops, something went wrong.