Commits (67)
build/
dist/
node_modules/
public/assets/
......@@ -2,7 +2,7 @@
/*.tgz
/.nyc_output/
/.tscache/
/build
/dist
/coverage
/node_modules
/public
......
......@@ -27,7 +27,7 @@ Build:
artifacts:
name: ${CI_PROJECT_PATH_SLUG}-${CI_PIPELINE_ID}-build
paths:
- build/
- dist/
script:
- npm run build
......@@ -108,13 +108,17 @@ Node 12.x (LTS):
<<: *compat
image: node:12
Node 14.x (current):
Node 14.x (LTS):
<<: *compat
image: node:14
Node 15.x (current):
<<: *compat
image: node:15
Release:
stage: release
image: node:12
image: node:14
only:
- web
variables:
......
......@@ -3,7 +3,7 @@
/package-lock.json
# compiled files
/build
/dist
/coverage
/public/**/*.html
/public/assets
......
# html-validate changelog
## [4.0.0](https://gitlab.com/html-validate/html-validate/compare/v3.5.0...v4.0.0) (2020-11-07)
### ⚠ BREAKING CHANGES
- **config:** With this release any custom configuration files will no longer
automatically extend `html-validate:recommended`.
The previous behaviour was to to always merge with the default configuration
containing `extends: ["html-validate:recommended"]`. This is counter-intuitive
when adding a blank `{}` `.htmlvalidate.json` configuration file (or a file with
`extends: []`). The new behaviour is to not apply default configuration if
another configuration is found.
To retain the previous behaviour you must ensure your configuration contains
`extends: ["html-validate:recommended"]`. Users who have `root: true` are not
affected. _If unsure: test your configuration by deliberatly introducing and
error and verify it is detected_.
For CLI users: ensure your `.htmlvalidate.json` configuration files are updated.
For IDE integration users: ensure your `.htmlvalidate.json` configuration files
are updated.
For `CLI` API users: same as with CLI the configuration loading has changed and
all users must update their `.htmlvalidate.json` accordingly.
For `HtmlValidate` API users: you are most likely not affected, only if both of
the following conditions are true you need to take care to ensure any
`.htmlvalidate.json` is updated:
1. you are using `validateFile` or supply filenames to other validation
functions.
2. you allow user-supplied configurations (or use them yourself) via
`.htmlvalidate.json` (default unless `root: true` is set in the configuration
object passed to `new HtmlValidate(..)`)
The `ConfigLoader` API has also been updated and `fromTarget` may now return
`null` if no configuration file was found.
- The `build` folder has been renamed to `dist`.
This affects API users only and in general should not be an issue unless
importing files via full path. In that case replace `import 'html-validate/build/...'` with `import 'html-validate/dist/...` but in general
those imports are discouraged.
Instead users should import only via `import { ... } from "html-validate"` and file an issue
if an export is missing.
This does not affect the `elements` imports which is considered a safe to import
as-is.
- Only node 10 or later is supported
### Features
- new utility function `ruleExists` to test presence of bundled rules ([09aad04](https://gitlab.com/html-validate/html-validate/commit/09aad040f201f91bdf47a4b0cf8e79ee05b9ff9c))
- **rules:** new helper `isHTMLHidden` ([ae20335](https://gitlab.com/html-validate/html-validate/commit/ae20335fbe45f368ef29844ce23541d41387899f))
- **shim:** add new export `html-validate/test-utils` exposing test-utils ([30f5d40](https://gitlab.com/html-validate/html-validate/commit/30f5d40379273c36871a487a55d83eb641fde037))
- **shim:** expose all event structures in shim ([294bb0d](https://gitlab.com/html-validate/html-validate/commit/294bb0d9ac40034d9863195d15fbdf9afa1e4d20))
- **shim:** expose metadata structures ([271e521](https://gitlab.com/html-validate/html-validate/commit/271e521795e47d539ac3cab73be7091269845cd6))
### Bug Fixes
- **config:** dont automatically apply `extends: ["html-validate:recommended"]` ([fcad0b2](https://gitlab.com/html-validate/html-validate/commit/fcad0b2a71bb007237058039eb907d8623e9188c)), closes [#98](https://gitlab.com/html-validate/html-validate/issues/98)
- require node 10 ([d1a48b1](https://gitlab.com/html-validate/html-validate/commit/d1a48b18353d5888bc25a133377aef622f926282))
- **rules:** `input-missing-label` handles multiple labels ([a6af2da](https://gitlab.com/html-validate/html-validate/commit/a6af2da352e1ed86e7f17c2018ddd2a925a49397))
- **rules:** `input-missing-label` ignores hidden `<input>` ([41c39e9](https://gitlab.com/html-validate/html-validate/commit/41c39e916fdf3579ec31d6fc6f36d951e92fd497))
- **rules:** `input-missing-label` requires label to be non-hidden ([ff5e855](https://gitlab.com/html-validate/html-validate/commit/ff5e8559c7ee3039d0ef515f5ed45bcd0c3b8724)), closes [#99](https://gitlab.com/html-validate/html-validate/issues/99)
### Miscellaneous Chores
- migrate to `dist` folder ([3c6787c](https://gitlab.com/html-validate/html-validate/commit/3c6787c27e0c4e68c8c33318df06065ce408aefa))
# [3.5.0](https://gitlab.com/html-validate/html-validate/compare/v3.4.1...v3.5.0) (2020-10-18)
### Features
......
#!/usr/bin/env node
"use strict";
require("../build/cli/html-validate");
require("../dist/cli/html-validate");
......@@ -23,8 +23,7 @@ if (!report.valid) {
files, load plugins, runs any transformations etc and is very similar to using
the CLI tool (in fact, the CLI tool uses this very API).
A default configuration object may optionally be passed to the `HtmlValidate`
constructor:
A configuration object may optionally be passed to the `HtmlValidate` constructor:
```typescript
const htmlvalidate = new HtmlValidate({
......@@ -32,7 +31,8 @@ const htmlvalidate = new HtmlValidate({
});
```
If set, all configuration will inherit from this configuration.
If set, it will be used as configuration unless a configuration could be read from `.htmlvalidate.json` files.
Set `root: true` to prevent configuration files to be searched.
## Validating strings and other sources
......@@ -99,7 +99,7 @@ formatted string:
```typescript
import { HtmlValidate } from "html-validate";
import text from "html-validate/build/formatters/text";
import text from "html-validate/dist/formatters/text";
const htmlvalidate = new HtmlValidate();
const report = htmlvalidate.validateFile("myfile.html");
......@@ -111,7 +111,7 @@ Using the CLI API there is a factory function to retrieve formatters (see
`html-validate --help` for details about the format):
```typescript
import { getFormatter } from "html-validate/build/cli/formatter";
import { getFormatter } from "html-validate/dist/cli/formatter";
const stylish = getFormatter("stylish");
console.log(stylish(report));
......@@ -150,7 +150,7 @@ tests:
```typescript
import { HtmlValidate } from "html-validate";
import "html-validate/build/matchers";
import "html-validate/jest";
const config = {
rules: {
......
const chalk = require("chalk");
const HtmlValidate = require("../../../../build/htmlvalidate").default;
const codeframe = require("../../../../build/formatters/codeframe").default;
const HtmlValidate = require("../../../../dist/htmlvalidate").default;
const codeframe = require("../../../../dist/formatters/codeframe").default;
module.exports = function generateValidationResultsProcessor(log, validateMap) {
return {
......
const a17y = require("../../../build/config/presets/a17y");
const document = require("../../../build/config/presets/document");
const recommended = require("../../../build/config/presets/recommended");
const standard = require("../../../build/config/presets/standard");
const a17y = require("../../../dist/config/presets/a17y");
const document = require("../../../dist/config/presets/document");
const recommended = require("../../../dist/config/presets/recommended");
const standard = require("../../../dist/config/presets/standard");
/* sort order */
const availablePresets = ["recommended", "standard", "a17y", "document"];
......
......@@ -20,6 +20,27 @@ Adds a new CLI service command:
Validates all `.html` and `.vue` files in the `src` folder. Patterns can be
overwritten by passing them as positional arguments.
## Using [`nuxt`](https://nuxtjs.org/)
yarn add --dev @nuxtjs/html-validator
Then add the Nuxt module to your `nuxt.config.js`:
```js
export default {
buildModules: ["@nuxtjs/html-validator"],
htmlValidator: {
options: {
// you can pass options directly to `html-validate`
},
},
};
```
You can find more details in [the documentation](https://html-validator.nuxtjs.org/).
The module will then validate all server-rendered and server-generated HTML with `html-validate`.
## Manual configuration
npm install html-validate-vue
......
......@@ -44,7 +44,7 @@ it("should give error when using <div> as content", () => {
When using Jest in particular there are helper functions to make it even easier:
```js
require("html-validate/build/matchers");
require("html-validate/jest");
it("should give error when using <div> as content", () => {
const report = htmlvalidate.validateString("<my-component><div>lorem ipsum</div></my-component>");
......
......@@ -2,6 +2,31 @@
exports[`docs/rules/input-missing-label.md inline validation: correct 1`] = `Array []`;
exports[`docs/rules/input-missing-label.md inline validation: hidden 1`] = `
Array [
Object {
"errorCount": 1,
"filePath": "inline",
"messages": Array [
Object {
"column": 2,
"context": undefined,
"line": 2,
"message": "<input> element has label but <label> element is hidden",
"offset": 59,
"ruleId": "input-missing-label",
"selector": "#my-input",
"severity": 2,
"size": 5,
},
],
"source": "<label for=\\"my-input\\" aria-hidden=\\"true\\">My field</label>
<input id=\\"my-input\\" type=\\"text\\">",
"warningCount": 0,
},
]
`;
exports[`docs/rules/input-missing-label.md inline validation: incorrect 1`] = `
Array [
Object {
......
......@@ -26,6 +26,8 @@ markup["correct"] = `<!-- label with descendant -->
<label for="my-field">My field</label>
<input id="my-field" type="text">
</div>`;
markup["hidden"] = `<label for="my-input" aria-hidden="true">My field</label>
<input id="my-input" type="text">`;
describe("docs/rules/input-missing-label.md", () => {
it("inline validation: incorrect", () => {
......@@ -40,4 +42,10 @@ describe("docs/rules/input-missing-label.md", () => {
const report = htmlvalidate.validateString(markup["correct"]);
expect(report.results).toMatchSnapshot();
});
it("inline validation: hidden", () => {
expect.assertions(1);
const htmlvalidate = new HtmlValidate({"rules":{"input-missing-label":"error"}});
const report = htmlvalidate.validateString(markup["hidden"]);
expect(report.results).toMatchSnapshot();
});
});
......@@ -58,3 +58,13 @@ Examples of **correct** code for this rule:
</div>
</validate>
### Hidden labels
This rule requires labels to be accessible, i.e. the label must not be `hidden` or `aria-hidden`.
If multiple labels are associated at least one of them must be accessible.
<validate name="hidden" rules="input-missing-label">
<label for="my-input" aria-hidden="true">My field</label>
<input id="my-input" type="text">
</validate>
/* eslint-disable-next-line import/export, import/no-unresolved */
export * from "./build/matchers";
export * from "./dist/matchers";
module.exports = require("./build/matchers");
module.exports = require("./dist/matchers");
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "html-validate",
"version": "3.5.0",
"version": "4.0.0",
"description": "html linter",
"keywords": [
"html",
......@@ -18,24 +18,25 @@
"bugs": {
"url": "https://gitlab.com/html-validate/html-validate/issues/new"
},
"main": "build/shim.js",
"main": "dist/shim.js",
"engines": {
"node": ">= 8.5"
"node": ">= 10.0"
},
"bin": {
"html-validate": "bin/html-validate.js"
},
"files": [
"bin",
"build",
"dist",
"elements",
"jest.{js,d.ts}",
"test-utils.{js,d.ts}",
"!*.snap",
"!*.spec.d.ts",
"!*.spec.js",
"!*.spec.ts",
"!__mocks__",
"!build/rules/**/*.d.ts"
"!dist/rules/**/*.d.ts"
],
"scripts": {
"build": "tsc",
......@@ -78,43 +79,44 @@
"extends": "@html-validate/semantic-release-config"
},
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@sidvind/better-ajv-errors": "^0.6.9",
"@babel/code-frame": "^7.10.4",
"@sidvind/better-ajv-errors": "^0.6.10",
"acorn-walk": "^8.0.0",
"ajv": "^6.10.0",
"ajv": "^6.12.6",
"chalk": "^4.0.0",
"deepmerge": "^4.0.0",
"eslint": "^7.0.0",
"espree": "^7.0.0",
"glob": "^7.1.3",
"inquirer": "^7.0.0",
"json-merge-patch": "^1.0.0",
"minimist": "^1.2.0"
"deepmerge": "^4.2.2",
"eslint": "^7.11.0",
"espree": "^7.3.0",
"glob": "^7.1.6",
"inquirer": "^7.3.3",
"json-merge-patch": "^1.0.1",
"minimist": "^1.2.5"
},
"devDependencies": {
"@babel/core": "7.12.3",
"@babel/preset-env": "7.12.1",
"@commitlint/cli": "11.0.0",
"@html-validate/commitlint-config": "1.0.3",
"@html-validate/eslint-config": "1.5.22",
"@html-validate/jest-config": "1.0.29",
"@html-validate/commitlint-config": "1.1.1",
"@html-validate/eslint-config": "2.0.0",
"@html-validate/jest-config": "1.0.33",
"@html-validate/prettier-config": "1.1.0",
"@html-validate/semantic-release-config": "1.0.41",
"@html-validate/semantic-release-config": "1.1.0",
"@lodder/grunt-postcss": "3.0.0",
"@types/babel__code-frame": "7.0.2",
"@types/estree": "0.0.45",
"@types/glob": "7.1.3",
"@types/inquirer": "7.3.1",
"@types/jest": "26.0.14",
"@types/jest": "26.0.15",
"@types/json-merge-patch": "0.0.5",
"@types/minimist": "1.2.0",
"@types/node": "11.15.32",
"autoprefixer": "9.8.6",
"@types/node": "11.15.35",
"autoprefixer": "10.0.1",
"babelify": "10.0.0",
"bootstrap-sass": "3.4.1",
"canonical-path": "1.0.0",
"cssnano": "4.1.10",
"dgeni": "0.4.12",
"dgeni-front-matter": "2.0.0",
"dgeni-front-matter": "2.0.2",
"dgeni-packages": "0.28.4",
"eslint-plugin-array-func": "3.1.7",
"eslint-plugin-node": "11.1.0",
......@@ -127,26 +129,26 @@
"grunt-cli": "1.3.2",
"grunt-contrib-connect": "3.0.0",
"grunt-contrib-copy": "1.0.0",
"grunt-postcss": "0.9.0",
"grunt-sass": "3.1.0",
"highlight.js": "10.2.1",
"highlight.js": "10.3.2",
"husky": "4.3.0",
"jest": "26.5.3",
"jest-diff": "26.5.2",
"jest": "26.6.3",
"jest-diff": "26.6.2",
"jquery": "3.5.1",
"lint-staged": "10.4.2",
"lint-staged": "10.5.1",
"load-grunt-tasks": "5.1.0",
"marked": "1.2.0",
"marked": "1.2.3",
"minimatch": "3.0.4",
"postcss": "8.1.6",
"prettier": "2.1.2",
"pretty-format": "26.5.2",
"sass": "1.27.0",
"semantic-release": "17.2.1",
"pretty-format": "26.6.2",
"sass": "1.29.0",
"semantic-release": "17.2.2",
"serve-static": "1.14.1",
"stringmap": "0.2.2",
"strip-ansi": "6.0.0",
"ts-jest": "26.4.1",
"typescript": "4.0.3"
"ts-jest": "26.4.3",
"typescript": "4.0.5"
},
"jest": {
"preset": "@html-validate/jest-config",
......
......@@ -11,7 +11,7 @@ function statSync(dir: string): any {
* to test with */
const suffix = dir.replace(`${process.cwd()}${path.sep}`, "");
const found = mockDirectory.indexOf(suffix) >= 0;
const found = mockDirectory.includes(suffix);
return {
isDirectory() {
return found;
......
import fs from "fs";
import { ConfigData } from "../config";
import HtmlValidate from "../htmlvalidate";
import { CLI } from "./cli";
......@@ -24,9 +25,14 @@ describe("CLI", () => {
it("should use configuration file", () => {
expect.assertions(3);
const customConfig: ConfigData = {
rules: {
foo: "error",
},
};
const readFileSync = jest
.spyOn(fs, "readFileSync")
.mockImplementation(() => '{"rules": {"foo": "error"}}');
.mockImplementation(() => JSON.stringify(customConfig));
const cli = new CLI({
configFile: "config.json",
});
......