Skip to content

Commit

Permalink
fix: improved tag-pair rule line numbers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Kimbrell committed Apr 15, 2024
1 parent a5bf548 commit be53ea0
Show file tree
Hide file tree
Showing 11 changed files with 1,910 additions and 1,177 deletions.
3 changes: 3 additions & 0 deletions __tests__/examples/tag-pair/missing-closing-tag/document.html
@@ -0,0 +1,3 @@
<div>
<div>1</div>
<div>2</div>
15 changes: 15 additions & 0 deletions __tests__/examples/tag-pair/missing-closing-tag/errors.js
@@ -0,0 +1,15 @@
module.exports = [
{
type: 'error',
message: 'Tag must be paired, missing: [ </div> ], start tag match failed [ <div> ] on line 1.',
raw: '<div>',
evidence: '<div>',
line: 1,
col: 1,
rule: {
id: 'tag-pair',
description: 'Tag must be paired.',
link: 'https://thecapsule.email/docs/codes/tag-pair'
}
}
]
@@ -0,0 +1,4 @@
<div>
<div>test</div>
<span>1
</div>
15 changes: 15 additions & 0 deletions __tests__/examples/tag-pair/missing-nested-closing-tag/errors.js
@@ -0,0 +1,15 @@
module.exports = [
{
type: 'error',
message: 'Tag must be paired, missing: [ </span> ], start tag match failed [ <span> ] on line 3.',
raw: '<span>',
evidence: ' <span>1',
line: 3,
col: 5,
rule: {
id: 'tag-pair',
description: 'Tag must be paired.',
link: 'https://thecapsule.email/docs/codes/tag-pair'
}
}
]
4 changes: 4 additions & 0 deletions __tests__/examples/tag-pair/missing-opening-tag/document.html
@@ -0,0 +1,4 @@
<div>
<div>123</div>
</div>
</div>
15 changes: 15 additions & 0 deletions __tests__/examples/tag-pair/missing-opening-tag/errors.js
@@ -0,0 +1,15 @@
module.exports = [
{
type: 'error',
message: 'Tag must be paired, no start tag: [ </div> ]',
raw: '</div>',
evidence: '</div>',
line: 4,
col: 1,
rule: {
id: 'tag-pair',
description: 'Tag must be paired.',
link: 'https://thecapsule.email/docs/codes/tag-pair'
}
}
]
18 changes: 15 additions & 3 deletions __tests__/rules.spec.ts
Expand Up @@ -45,9 +45,7 @@ describe('Rule: "head-no-duplicates"', () => {
it('Throws errors for duplicate <head> tags.', () => {
rule('head-no-duplicates');
});
});

describe('Rule: "html-no-duplicates"', () => {

it('Throws errors for duplicate <html> tags.', () => {
rule('html-no-duplicates');
});
Expand Down Expand Up @@ -105,4 +103,18 @@ describe('Rule: "freemarker-tags"', () => {
it('Throws errors for invalid freemarker tags.', () => {
rule('freemarker-tags');
});
});

describe('Rule: "tag-pair"', () => {
it('Throws errors when missing closing tag.', () => {
rule('tag-pair/missing-closing-tag');
});

it('Throws errors when missing nested closing tag.', () => {
rule('tag-pair/missing-nested-closing-tag');
});

it('Throws errors when missing closing tag.', () => {
rule('tag-pair/missing-opening-tag');
});
});
11 changes: 6 additions & 5 deletions demo/App.vue
Expand Up @@ -3,9 +3,10 @@ import { TextareaField } from '@vue-interface/textarea-field';
import { ref, watchEffect } from 'vue';
import { lint } from '../src/index';
const document = ref<string>(`
<p><a href="https://a.com/?a=1&amp;b=2&amp;b=2">test</a></p>
`);
const document = ref<string>(`<div>
<div>test</div>
<span>1
</div>`);
const errors = ref<any[]>();
Expand All @@ -16,10 +17,10 @@ watchEffect(() => {

<template>
<div class="p-8">
<TextareaField v-model="document" :autogrow="false" />
<TextareaField v-model="document" />
<div v-if="errors?.length" class="mt-4 p-4 rounded bg-rose-500 text-rose-100">
<div v-for="error in errors">
{{ error.message }} on line {{ error.line }} column {{ error.col}}
{{ error.message }} Line: {{ error.line }} Col: {{ error.col }}
</div>
</div>
</div>
Expand Down
30 changes: 15 additions & 15 deletions package.json
Expand Up @@ -36,42 +36,42 @@
},
"homepage": "https://github.com/ActiveEngagement/capsule-lint#readme",
"devDependencies": {
"@babel/preset-env": "^7.23.6",
"@babel/preset-typescript": "^7.23.3",
"@babel/preset-env": "^7.24.4",
"@babel/preset-typescript": "^7.24.1",
"@commitlint/config-conventional": "^17.8.1",
"@jest/globals": "^29.7.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@semantic-release/npm": "^10.0.6",
"@types/html-minifier": "^4.0.5",
"@types/htmlhint": "^1.1.5",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.12",
"@types/js-beautify": "^1.14.3",
"@types/node": "^20.10.5",
"@types/node": "^20.12.7",
"@types/nunjucks": "^3.2.6",
"@vitejs/plugin-vue": "^4.5.2",
"@vitejs/plugin-vue": "^4.6.2",
"@vue-interface/eslint-config": "1.0.0-beta.4",
"@vue-interface/form-control": "1.0.0-beta.44",
"@vue-interface/textarea-field": "1.0.0-beta.13",
"autoprefixer": "^10.4.16",
"autoprefixer": "^10.4.19",
"babel-jest": "^29.7.0",
"chalk": "^4.1.2",
"commander": "^8.3.0",
"commitlint": "^17.8.1",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"husky": "^8.0.3",
"jest": "^29.7.0",
"peggy": "^3.0.2",
"postcss": "^8.4.32",
"postcss": "^8.4.38",
"semantic-release": "^21.1.2",
"tailwindcss": "^3.4.0",
"ts-jest": "^29.1.1",
"tailwindcss": "^3.4.3",
"ts-jest": "^29.1.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
"vite": "^4.5.1",
"vite-plugin-dts": "^3.6.4",
"vue": "^3.3.13"
"typescript": "^5.4.5",
"vite": "^4.5.3",
"vite-plugin-dts": "^3.8.3",
"vue": "^3.4.22"
},
"dependencies": {
"htmlhint": "^1.1.4",
Expand Down

0 comments on commit be53ea0

Please sign in to comment.