mirror of
				https://github.com/theoludwig/html-w3c-validator.git
				synced 2025-05-21 23:21:29 +02:00 
			
		
		
		
	Compare commits
	
		
			11 Commits
		
	
	
		
			v1.5.1
			...
			e53c80d578
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| e53c80d578 | |||
| 5f63d749e8 | |||
| 67b70feb15 | |||
| 6b28c6d224 | |||
| a1340b2729 | |||
| 92320385b5 | |||
| 8934ac1b7a | |||
| 09731d4749 | |||
| 2e0e136355 | |||
| 04a2742e46 | |||
| 75f862d0fd | 
| @@ -1,16 +1,19 @@ | |||||||
| { | { | ||||||
|   "extends": ["conventions", "prettier"], |   "root": true, | ||||||
|   "plugins": ["prettier", "import", "unicorn"], |   "extends": ["conventions"], | ||||||
|  |   "plugins": ["import", "promise", "unicorn"], | ||||||
|  |   "rules": { | ||||||
|  |     "import/extensions": ["error", "always"], | ||||||
|  |     "unicorn/prevent-abbreviations": "error" | ||||||
|  |   }, | ||||||
|  |   "overrides": [ | ||||||
|  |     { | ||||||
|  |       "files": ["*.ts", "*.tsx"], | ||||||
|  |       "parser": "@typescript-eslint/parser", | ||||||
|  |       "plugins": ["@typescript-eslint"], | ||||||
|       "parserOptions": { |       "parserOptions": { | ||||||
|         "project": "./tsconfig.json" |         "project": "./tsconfig.json" | ||||||
|   }, |  | ||||||
|   "env": { |  | ||||||
|     "node": true |  | ||||||
|   }, |  | ||||||
|   "rules": { |  | ||||||
|     "prettier/prettier": "error", |  | ||||||
|     "import/extensions": ["error", "always"], |  | ||||||
|     "unicorn/prevent-abbreviations": "error", |  | ||||||
|     "unicorn/prefer-node-protocol": "error" |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |   ] | ||||||
|  | } | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/build.yml
									
									
									
									
										vendored
									
									
								
							| @@ -10,10 +10,10 @@ jobs: | |||||||
|   build: |   build: | ||||||
|     runs-on: "ubuntu-latest" |     runs-on: "ubuntu-latest" | ||||||
|     steps: |     steps: | ||||||
|       - uses: "actions/checkout@v4.1.1" |       - uses: "actions/checkout@v4.1.6" | ||||||
|  |  | ||||||
|       - name: "Setup Node.js" |       - name: "Setup Node.js" | ||||||
|         uses: "actions/setup-node@v4.0.1" |         uses: "actions/setup-node@v4.0.2" | ||||||
|         with: |         with: | ||||||
|           node-version: "lts/*" |           node-version: "lts/*" | ||||||
|           cache: "npm" |           cache: "npm" | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								.github/workflows/lint.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										5
									
								
								.github/workflows/lint.yml
									
									
									
									
										vendored
									
									
								
							| @@ -10,10 +10,10 @@ jobs: | |||||||
|   lint: |   lint: | ||||||
|     runs-on: "ubuntu-latest" |     runs-on: "ubuntu-latest" | ||||||
|     steps: |     steps: | ||||||
|       - uses: "actions/checkout@v4.1.1" |       - uses: "actions/checkout@v4.1.6" | ||||||
|  |  | ||||||
|       - name: "Setup Node.js" |       - name: "Setup Node.js" | ||||||
|         uses: "actions/setup-node@v4.0.1" |         uses: "actions/setup-node@v4.0.2" | ||||||
|         with: |         with: | ||||||
|           node-version: "lts/*" |           node-version: "lts/*" | ||||||
|           cache: "npm" |           cache: "npm" | ||||||
| @@ -23,6 +23,5 @@ jobs: | |||||||
|  |  | ||||||
|       - run: 'npm run lint:commit -- --to "${{ github.sha }}"' |       - run: 'npm run lint:commit -- --to "${{ github.sha }}"' | ||||||
|       - run: "npm run lint:editorconfig" |       - run: "npm run lint:editorconfig" | ||||||
|       - run: "npm run lint:markdown" |  | ||||||
|       - run: "npm run lint:eslint" |       - run: "npm run lint:eslint" | ||||||
|       - run: "npm run lint:prettier" |       - run: "npm run lint:prettier" | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/release.yml
									
									
									
									
										vendored
									
									
								
							| @@ -13,13 +13,13 @@ jobs: | |||||||
|       pull-requests: "write" |       pull-requests: "write" | ||||||
|       id-token: "write" |       id-token: "write" | ||||||
|     steps: |     steps: | ||||||
|       - uses: "actions/checkout@v4.1.1" |       - uses: "actions/checkout@v4.1.6" | ||||||
|         with: |         with: | ||||||
|           fetch-depth: 0 |           fetch-depth: 0 | ||||||
|           persist-credentials: false |           persist-credentials: false | ||||||
|  |  | ||||||
|       - name: "Setup Node.js" |       - name: "Setup Node.js" | ||||||
|         uses: "actions/setup-node@v4.0.1" |         uses: "actions/setup-node@v4.0.2" | ||||||
|         with: |         with: | ||||||
|           node-version: "lts/*" |           node-version: "lts/*" | ||||||
|           cache: "npm" |           cache: "npm" | ||||||
|   | |||||||
							
								
								
									
										4
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/test.yml
									
									
									
									
										vendored
									
									
								
							| @@ -10,10 +10,10 @@ jobs: | |||||||
|   test: |   test: | ||||||
|     runs-on: "ubuntu-latest" |     runs-on: "ubuntu-latest" | ||||||
|     steps: |     steps: | ||||||
|       - uses: "actions/checkout@v4.1.1" |       - uses: "actions/checkout@v4.1.6" | ||||||
|  |  | ||||||
|       - name: "Setup Node.js" |       - name: "Setup Node.js" | ||||||
|         uses: "actions/setup-node@v4.0.1" |         uses: "actions/setup-node@v4.0.2" | ||||||
|         with: |         with: | ||||||
|           node-version: "lts/*" |           node-version: "lts/*" | ||||||
|           cache: "npm" |           cache: "npm" | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								.husky/commit-msg
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										3
									
								
								.husky/commit-msg
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | #!/usr/bin/env sh | ||||||
|  |  | ||||||
|  | npm run lint:commit -- --edit | ||||||
							
								
								
									
										4
									
								
								.husky/pre-commit
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										4
									
								
								.husky/pre-commit
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,4 @@ | |||||||
|  | #!/usr/bin/env sh | ||||||
|  |  | ||||||
|  | npm run lint:staged | ||||||
|  | npm run build:typescript | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "*": ["editorconfig-checker"], |   "**/*": ["editorconfig-checker", "prettier --write --ignore-unknown"], | ||||||
|   "*.{js,ts,jsx,tsx}": ["prettier --write", "eslint --fix"], |   "**/*.{js,jsx,ts,tsx}": [ | ||||||
|   "*.{yml,json}": ["prettier --write"], |     "eslint --fix --max-warnings 0 --report-unused-disable-directives" | ||||||
|   "*.md": ["prettier --write", "markdownlint --dot --fix"] |   ] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,11 +0,0 @@ | |||||||
| { |  | ||||||
|   "config": { |  | ||||||
|     "extends": "markdownlint/style/prettier", |  | ||||||
|     "relative-links": true, |  | ||||||
|     "default": true, |  | ||||||
|     "MD033": false |  | ||||||
|   }, |  | ||||||
|   "globs": ["**/*.{md,mdx}"], |  | ||||||
|   "ignores": ["**/node_modules"], |  | ||||||
|   "customRules": ["markdownlint-rule-relative-links"] |  | ||||||
| } |  | ||||||
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| # MIT License | # MIT License | ||||||
|  |  | ||||||
| Copyright (c) Théo LUDWIG | Copyright (c) Théo LUDWIG <contact@theoludwig.fr> | ||||||
|  |  | ||||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | Permission is hereby granted, free of charge, to any person obtaining a copy | ||||||
| of this software and associated documentation files (the "Software"), to deal | of this software and associated documentation files (the "Software"), to deal | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,9 +1,7 @@ | |||||||
| <h1 align="center">html-w3c-validator</h1> | <h1 align="center">html-w3c-validator</h1> | ||||||
|  |  | ||||||
| <p align="center"> | <p align="center"> | ||||||
|   <strong>CLI for validating multiple html pages using <a href="https://validator.w3.org/">validator.w3.org</a>.</strong> |   <strong>CLI for validating HTML pages using <a href="https://validator.w3.org/">validator.w3.org</a>.</strong> | ||||||
| </p> |  | ||||||
|  |  | ||||||
| </p> | </p> | ||||||
|  |  | ||||||
| <p align="center"> | <p align="center"> | ||||||
| @@ -22,11 +20,11 @@ | |||||||
|  |  | ||||||
| ## 📜 About | ## 📜 About | ||||||
|  |  | ||||||
| **html-w3c-validator** is a CLI tool to validate multiple html pages using [validator.w3.org](https://validator.w3.org/). | **html-w3c-validator** is a CLI tool to validate HTML pages using [validator.w3.org](https://validator.w3.org/). | ||||||
|  |  | ||||||
| You might use a JavaScript framework or simply use HTML but **you should always validate your production HTML** and this validation should be part of your CI/CD pipeline (tests, linting, etc.). | You might use a JavaScript framework or simply use HTML but **you should always validate your production HTML** and this validation should be part of your CI/CD pipeline (tests, linting, etc.). | ||||||
|  |  | ||||||
| ### Why should I validate my HTML pages? | ### Why is HTML page validation important? | ||||||
|  |  | ||||||
| Quote from [https://validator.w3.org/docs/help.html#why-validate](https://validator.w3.org/docs/help.html#why-validate): | Quote from [https://validator.w3.org/docs/help.html#why-validate](https://validator.w3.org/docs/help.html#why-validate): | ||||||
|  |  | ||||||
| @@ -40,7 +38,7 @@ You can combine **html-w3c-validator** with [start-server-and-test](https://gith | |||||||
|  |  | ||||||
| ### Prerequisites | ### Prerequisites | ||||||
|  |  | ||||||
| - [Node.js](https://nodejs.org/) >= 16.0.0 | [Node.js](https://nodejs.org/) >= 16.0.0 | ||||||
|  |  | ||||||
| ### Installation (with [start-server-and-test](https://github.com/bahmutov/start-server-and-test)) | ### Installation (with [start-server-and-test](https://github.com/bahmutov/start-server-and-test)) | ||||||
|  |  | ||||||
| @@ -59,8 +57,8 @@ npm install --save-dev html-w3c-validator start-server-and-test | |||||||
|     "start": "serve \"./build\"", |     "start": "serve \"./build\"", | ||||||
|  |  | ||||||
|     // Command to validate your HTML pages |     // Command to validate your HTML pages | ||||||
|     "test:html-w3c-validator": "start-server-and-test \"start\" \"http://127.0.0.1:3000\" \"html-w3c-validator\"" |     "test:html-w3c-validator": "start-server-and-test \"start\" \"http://127.0.0.1:3000\" \"html-w3c-validator\"", | ||||||
|   } |   }, | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| @@ -68,13 +66,16 @@ npm install --save-dev html-w3c-validator start-server-and-test | |||||||
|  |  | ||||||
| ```jsonc | ```jsonc | ||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/master/schema/html-w3c-validatorrc-schema.json", | ||||||
|  |  | ||||||
|  |   // URLs to validate. | ||||||
|   "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/about"], |   "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/about"], | ||||||
|  |  | ||||||
|   // You can also specify HTML files instead of URLs |   // Files to validate. | ||||||
|   "files": ["./index.html", "./about.html"], |   "files": ["./index.html", "./about.html"], | ||||||
|  |  | ||||||
|   // Specify the severities of the validator (default: ["warning", "error"]) |   // Specify the severities of the validator messages to report. (default: ["warning", "error"]) | ||||||
|   "severities": ["info", "warning", "error"] |   "severities": ["info", "warning", "error"], | ||||||
| } | } | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| @@ -98,6 +99,7 @@ See the [./example](./example) folder for practical usage. | |||||||
| ### Options | ### Options | ||||||
|  |  | ||||||
| ```text | ```text | ||||||
|  | --current-working-directory <path>  The current working directory (default: `process.cwd()`). | ||||||
| -V, --version                       Output the version number. | -V, --version                       Output the version number. | ||||||
| -h, --help                          Display help for command. | -h, --help                          Display help for command. | ||||||
| ``` | ``` | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/about"], |   "urls": ["http://127.0.0.1:3000/", "http://127.0.0.1:3000/about"], | ||||||
|   "files": ["./build/index.html", "./build/about.html"] |   "files": ["./build/index.html", "./build/about.html"] | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										300
									
								
								example/package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										300
									
								
								example/package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -6,7 +6,7 @@ | |||||||
|     "test:html-w3c-validator": "start-server-and-test \"start\" \"http://127.0.0.1:3000\" \"html-w3c-validator\"" |     "test:html-w3c-validator": "start-server-and-test \"start\" \"http://127.0.0.1:3000\" \"html-w3c-validator\"" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "serve": "14.2.1", |     "serve": "14.2.3", | ||||||
|     "start-server-and-test": "2.0.3", |     "start-server-and-test": "2.0.3", | ||||||
|     "html-w3c-validator": "file:.." |     "html-w3c-validator": "file:.." | ||||||
|   } |   } | ||||||
|   | |||||||
							
								
								
									
										7517
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										7517
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										68
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										68
									
								
								package.json
									
									
									
									
									
								
							| @@ -1,7 +1,7 @@ | |||||||
| { | { | ||||||
|   "name": "html-w3c-validator", |   "name": "html-w3c-validator", | ||||||
|   "version": "0.0.0-development", |   "version": "0.0.0-development", | ||||||
|   "description": "CLI for validating multiple html pages using validator.w3.org.", |   "description": "CLI for validating HTML pages using validator.w3.org.", | ||||||
|   "public": true, |   "public": true, | ||||||
|   "types": "module", |   "types": "module", | ||||||
|   "type": "module", |   "type": "module", | ||||||
| @@ -33,61 +33,55 @@ | |||||||
|     "provenance": true |     "provenance": true | ||||||
|   }, |   }, | ||||||
|   "engines": { |   "engines": { | ||||||
|     "node": ">=16.0.0", |     "node": ">=16.0.0" | ||||||
|     "npm": ">=9.0.0" |  | ||||||
|   }, |   }, | ||||||
|   "scripts": { |   "scripts": { | ||||||
|     "build": "rimraf ./build && swc ./src --out-dir ./build", |     "build": "swc ./src --out-dir ./build --strip-leading-paths --delete-dir-on-start", | ||||||
|     "build:typescript": "tsc", |     "build:typescript": "tsc", | ||||||
|     "start": "node --enable-source-maps build/index.js", |     "start": "node --enable-source-maps build/index.js", | ||||||
|     "lint:commit": "commitlint", |     "lint:commit": "commitlint", | ||||||
|     "lint:editorconfig": "editorconfig-checker", |     "lint:editorconfig": "editorconfig-checker", | ||||||
|     "lint:markdown": "markdownlint-cli2", |  | ||||||
|     "lint:eslint": "eslint . --max-warnings 0 --report-unused-disable-directives --ignore-path .gitignore", |     "lint:eslint": "eslint . --max-warnings 0 --report-unused-disable-directives --ignore-path .gitignore", | ||||||
|     "lint:prettier": "prettier . --check", |     "lint:prettier": "prettier . --check", | ||||||
|     "lint:staged": "lint-staged", |     "lint:staged": "lint-staged", | ||||||
|     "test": "node --enable-source-maps --test build/", |     "test": "node --enable-source-maps --test", | ||||||
|     "release": "semantic-release" |     "release": "semantic-release", | ||||||
|  |     "postinstall": "husky", | ||||||
|  |     "prepublishOnly": "pinst --disable", | ||||||
|  |     "postpublish": "pinst --enable" | ||||||
|   }, |   }, | ||||||
|   "dependencies": { |   "dependencies": { | ||||||
|     "chalk": "5.3.0", |     "chalk": "5.3.0", | ||||||
|     "clipanion": "3.2.1", |     "clipanion": "3.2.1", | ||||||
|     "html-validator": "6.0.1", |  | ||||||
|     "log-symbols": "6.0.0", |     "log-symbols": "6.0.0", | ||||||
|     "ora": "8.0.1", |     "ora": "8.0.1", | ||||||
|     "read-pkg": "9.0.1", |     "read-pkg": "9.0.1", | ||||||
|     "table": "6.8.1" |     "table": "6.8.2" | ||||||
|   }, |   }, | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|     "@commitlint/cli": "18.4.3", |     "@commitlint/cli": "19.2.2", | ||||||
|     "@commitlint/config-conventional": "18.4.3", |     "@commitlint/config-conventional": "19.2.2", | ||||||
|     "@swc/cli": "0.1.63", |     "@swc/cli": "0.3.12", | ||||||
|     "@swc/core": "1.3.101", |     "@swc/core": "1.5.7", | ||||||
|     "@tsconfig/strictest": "2.0.2", |     "@tsconfig/strictest": "2.0.5", | ||||||
|     "@types/html-validator": "5.0.6", |     "@types/node": "20.12.12", | ||||||
|     "@types/mock-fs": "4.13.4", |     "@types/sinon": "17.0.3", | ||||||
|     "@types/node": "20.10.5", |     "@typescript-eslint/eslint-plugin": "7.10.0", | ||||||
|     "@types/sinon": "17.0.2", |     "@typescript-eslint/parser": "7.10.0", | ||||||
|     "@typescript-eslint/eslint-plugin": "6.16.0", |     "editorconfig-checker": "5.1.5", | ||||||
|     "@typescript-eslint/parser": "6.16.0", |     "eslint": "8.57.0", | ||||||
|     "editorconfig-checker": "5.1.2", |     "eslint-config-conventions": "14.2.0", | ||||||
|     "eslint": "8.56.0", |  | ||||||
|     "eslint-config-conventions": "13.1.0", |  | ||||||
|     "eslint-config-prettier": "9.1.0", |  | ||||||
|     "eslint-plugin-import": "2.29.1", |     "eslint-plugin-import": "2.29.1", | ||||||
|     "eslint-plugin-prettier": "5.1.2", |  | ||||||
|     "eslint-plugin-promise": "6.1.1", |     "eslint-plugin-promise": "6.1.1", | ||||||
|     "eslint-plugin-unicorn": "50.0.1", |     "eslint-plugin-unicorn": "53.0.0", | ||||||
|     "execa": "8.0.1", |     "execa": "9.1.0", | ||||||
|     "lint-staged": "15.2.0", |     "husky": "9.0.11", | ||||||
|     "markdownlint-cli2": "0.11.0", |     "lint-staged": "15.2.4", | ||||||
|     "markdownlint-rule-relative-links": "2.1.2", |     "pinst": "3.0.0", | ||||||
|     "mock-fs": "5.2.0", |     "prettier": "3.2.5", | ||||||
|     "prettier": "3.1.1", |     "semantic-release": "23.1.1", | ||||||
|     "rimraf": "5.0.5", |     "serve": "14.2.3", | ||||||
|     "semantic-release": "22.0.12", |     "sinon": "18.0.0", | ||||||
|     "serve": "14.2.1", |     "typescript": "5.4.5" | ||||||
|     "sinon": "17.0.1", |  | ||||||
|     "typescript": "5.3.3" |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										50
									
								
								schema/html-w3c-validatorrc-schema.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								schema/html-w3c-validatorrc-schema.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | { | ||||||
|  |   "$schema": "http://json-schema.org/draft-07/schema#", | ||||||
|  |   "$id": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/master/schema/html-w3c-validatorrc-schema.json", | ||||||
|  |   "title": "html-w3c-validator configuration schema", | ||||||
|  |   "type": "object", | ||||||
|  |   "properties": { | ||||||
|  |     "$schema": { | ||||||
|  |       "description": "JSON Schema URI", | ||||||
|  |       "type": "string", | ||||||
|  |       "format": "uri", | ||||||
|  |       "default": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/master/schema/html-w3c-validatorrc-schema.json" | ||||||
|  |     }, | ||||||
|  |     "urls": { | ||||||
|  |       "description": "URLs to validate.", | ||||||
|  |       "type": "array", | ||||||
|  |       "default": [], | ||||||
|  |       "minItems": 1, | ||||||
|  |       "items": { | ||||||
|  |         "description": "URL to validate.", | ||||||
|  |         "type": "string", | ||||||
|  |         "format": "uri", | ||||||
|  |         "minLength": 1 | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     "files": { | ||||||
|  |       "description": "Files to validate.", | ||||||
|  |       "type": "array", | ||||||
|  |       "minItems": 1, | ||||||
|  |       "default": [], | ||||||
|  |       "items": { | ||||||
|  |         "description": "File to validate.", | ||||||
|  |         "type": "string", | ||||||
|  |         "format": "uri-reference", | ||||||
|  |         "minLength": 1 | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     "severities": { | ||||||
|  |       "description": "Specify the severities to report.", | ||||||
|  |       "type": "array", | ||||||
|  |       "minItems": 1, | ||||||
|  |       "default": ["warning", "error"], | ||||||
|  |       "items": { | ||||||
|  |         "description": "Severity to report.", | ||||||
|  |         "type": "string", | ||||||
|  |         "enum": ["error", "warning", "info"] | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   }, | ||||||
|  |   "additionalProperties": false | ||||||
|  | } | ||||||
| @@ -1,19 +1,15 @@ | |||||||
| import path from "node:path" |  | ||||||
| import fs from "node:fs" | import fs from "node:fs" | ||||||
|  | import path from "node:path" | ||||||
|  |  | ||||||
| import { Command, Option } from "clipanion" |  | ||||||
| import * as typanion from "typanion" |  | ||||||
| import chalk from "chalk" | import chalk from "chalk" | ||||||
| import ora from "ora" | import { Command, Option } from "clipanion" | ||||||
| import logSymbols from "log-symbols" | import logSymbols from "log-symbols" | ||||||
| import type { | import ora from "ora" | ||||||
|   ValidationMessageLocationObject, |  | ||||||
|   ParsedJsonAsValidationResults, |  | ||||||
| } from "html-validator" |  | ||||||
| import validateHTML from "html-validator" |  | ||||||
| import { table } from "table" | import { table } from "table" | ||||||
|  | import * as typanion from "typanion" | ||||||
|  |  | ||||||
| import { isExistingPath } from "./utils/isExistingPath.js" | import type { ValidateHTMLResult } from "./validateHTML.js" | ||||||
|  | import { getHTMLFromURL, validateHTML } from "./validateHTML.js" | ||||||
|  |  | ||||||
| export const CONFIG_FILE_NAME = ".html-w3c-validatorrc.json" | export const CONFIG_FILE_NAME = ".html-w3c-validatorrc.json" | ||||||
|  |  | ||||||
| @@ -50,7 +46,7 @@ const printResults = (results: Result[]): void => { | |||||||
| export class HTMLValidatorCommand extends Command { | export class HTMLValidatorCommand extends Command { | ||||||
|   static override usage = { |   static override usage = { | ||||||
|     description: |     description: | ||||||
|       "CLI for validating multiple html pages using <https://validator.w3.org/>.", |       "CLI for validating HTML pages using <https://validator.w3.org/>.", | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public currentWorkingDirectory = Option.String( |   public currentWorkingDirectory = Option.String( | ||||||
| @@ -65,22 +61,20 @@ export class HTMLValidatorCommand extends Command { | |||||||
|   public async execute(): Promise<number> { |   public async execute(): Promise<number> { | ||||||
|     const configPath = path.join(this.currentWorkingDirectory, CONFIG_FILE_NAME) |     const configPath = path.join(this.currentWorkingDirectory, CONFIG_FILE_NAME) | ||||||
|     try { |     try { | ||||||
|       if (!(await isExistingPath(configPath))) { |       let configData: string | ||||||
|  |       try { | ||||||
|  |         configData = await fs.promises.readFile(configPath, { | ||||||
|  |           encoding: "utf-8", | ||||||
|  |         }) | ||||||
|  |       } catch (error) { | ||||||
|         throw new Error( |         throw new Error( | ||||||
|           `No config file found at ${configPath}. Please create "${CONFIG_FILE_NAME}".`, |           `No config file found at ${configPath}. Please create "${CONFIG_FILE_NAME}".`, | ||||||
|         ) |         ) | ||||||
|       } |       } | ||||||
|       const configData = await fs.promises.readFile(configPath, { |  | ||||||
|         encoding: "utf-8", |  | ||||||
|       }) |  | ||||||
|       let config: Config = { urls: [], files: [] } |       let config: Config = { urls: [], files: [] } | ||||||
|       let isValidConfig = true |  | ||||||
|       try { |       try { | ||||||
|         config = JSON.parse(configData) |         config = JSON.parse(configData) | ||||||
|       } catch { |       } catch { | ||||||
|         isValidConfig = false |  | ||||||
|       } |  | ||||||
|       if (!isValidConfig) { |  | ||||||
|         throw new Error( |         throw new Error( | ||||||
|           `Invalid config file at "${configPath}". Please check the JSON syntax.`, |           `Invalid config file at "${configPath}". Please check the JSON syntax.`, | ||||||
|         ) |         ) | ||||||
| @@ -137,29 +131,25 @@ export class HTMLValidatorCommand extends Command { | |||||||
|       await Promise.all( |       await Promise.all( | ||||||
|         dataToValidate.map(async ({ data, type }) => { |         dataToValidate.map(async ({ data, type }) => { | ||||||
|           try { |           try { | ||||||
|             const options = { |             let result: ValidateHTMLResult | undefined | ||||||
|               format: "json" as "json" | undefined, |  | ||||||
|             } |  | ||||||
|             let result: ParsedJsonAsValidationResults | undefined |  | ||||||
|             if (type === "url") { |             if (type === "url") { | ||||||
|               result = await validateHTML({ |               result = await validateHTML({ | ||||||
|                 url: data, |                 htmlData: await getHTMLFromURL(data), | ||||||
|                 isLocal: true, |  | ||||||
|                 ...options, |  | ||||||
|               }) |               }) | ||||||
|             } else if (type === "file") { |             } else if (type === "file") { | ||||||
|               const htmlPath = path.resolve(this.currentWorkingDirectory, data) |               const htmlPath = path.resolve(this.currentWorkingDirectory, data) | ||||||
|               if (!(await isExistingPath(htmlPath))) { |               let html: string | ||||||
|  |               try { | ||||||
|  |                 html = await fs.promises.readFile(htmlPath, { | ||||||
|  |                   encoding: "utf-8", | ||||||
|  |                 }) | ||||||
|  |               } catch (error) { | ||||||
|                 throw new Error( |                 throw new Error( | ||||||
|                   `No file found at "${htmlPath}". Please check the path.`, |                   `No file found at "${htmlPath}". Please check the path.`, | ||||||
|                 ) |                 ) | ||||||
|               } |               } | ||||||
|               const html = await fs.promises.readFile(htmlPath, { |  | ||||||
|                 encoding: "utf-8", |  | ||||||
|               }) |  | ||||||
|               result = await validateHTML({ |               result = await validateHTML({ | ||||||
|                 data: html, |                 htmlData: html, | ||||||
|                 ...options, |  | ||||||
|               }) |               }) | ||||||
|             } else { |             } else { | ||||||
|               throw new Error("Invalid type") |               throw new Error("Invalid type") | ||||||
| @@ -194,10 +184,9 @@ export class HTMLValidatorCommand extends Command { | |||||||
|                   row.push(chalk.red(message.type)) |                   row.push(chalk.red(message.type)) | ||||||
|                 } |                 } | ||||||
|                 row.push(message.message) |                 row.push(message.message) | ||||||
|                 const violation = message as ValidationMessageLocationObject |                 if (message.extract != null) { | ||||||
|                 if (violation.extract != null) { |  | ||||||
|                   row.push( |                   row.push( | ||||||
|                     `line: ${violation.lastLine}, column: ${violation.firstColumn}-${violation.lastColumn}`, |                     `line: ${message.lastLine}, column: ${message.firstColumn}-${message.lastColumn}`, | ||||||
|                   ) |                   ) | ||||||
|                 } |                 } | ||||||
|                 messagesTable.push(row) |                 messagesTable.push(row) | ||||||
|   | |||||||
| @@ -1,7 +1,9 @@ | |||||||
| import test from "node:test" | import test from "node:test" | ||||||
| import assert from "node:assert/strict" | import assert from "node:assert/strict" | ||||||
| import path from "node:path" | import path from "node:path" | ||||||
|  | import fs from "node:fs" | ||||||
| import { PassThrough } from "node:stream" | import { PassThrough } from "node:stream" | ||||||
|  | import { fileURLToPath } from "node:url" | ||||||
|  |  | ||||||
| import sinon from "sinon" | import sinon from "sinon" | ||||||
| import { execa } from "execa" | import { execa } from "execa" | ||||||
| @@ -33,7 +35,10 @@ await test("html-w3c-validator", async (t) => { | |||||||
|     async () => { |     async () => { | ||||||
|       const exampleURL = new URL("../../example", import.meta.url) |       const exampleURL = new URL("../../example", import.meta.url) | ||||||
|       process.chdir(exampleURL.pathname) |       process.chdir(exampleURL.pathname) | ||||||
|       await execa("rimraf", ["node_modules"]) |       await fs.promises.rm( | ||||||
|  |         path.join(fileURLToPath(exampleURL), "node_modules"), | ||||||
|  |         { recursive: true, force: true }, | ||||||
|  |       ) | ||||||
|       await execa("npm", ["install"]) |       await execa("npm", ["install"]) | ||||||
|       const { exitCode } = await execa("npm", [ |       const { exitCode } = await execa("npm", [ | ||||||
|         "run", |         "run", | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "urls": [], |   "urls": [], | ||||||
|   "files": [] |   "files": [] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "files": "Invalid" |   "files": "Invalid" | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "files": ["./index.html"], |   "files": ["./index.html"], | ||||||
|   "severities": [] |   "severities": [] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "files": ["./index.html"], |   "files": ["./index.html"], | ||||||
|   "severities": ["errors-invalid"] |   "severities": ["errors-invalid"] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "urls": "Invalid" |   "urls": "Invalid" | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "files": ["./index.html"] |   "files": ["./index.html"] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "files": ["./build/index.html", "./build/about.html"] |   "files": ["./build/index.html", "./build/about.html"] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,3 +1,4 @@ | |||||||
| { | { | ||||||
|  |   "$schema": "https://raw.githubusercontent.com/theoludwig/html-w3c-validator/develop/schema/html-w3c-validatorrc-schema.json", | ||||||
|   "files": ["./build/index.html", "./build/about.html"] |   "files": ["./build/index.html", "./build/about.html"] | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,26 +0,0 @@ | |||||||
| import test from "node:test" |  | ||||||
| import assert from "node:assert/strict" |  | ||||||
|  |  | ||||||
| import fsMock from "mock-fs" |  | ||||||
|  |  | ||||||
| import { isExistingPath } from "../isExistingPath.js" |  | ||||||
|  |  | ||||||
| await test("utils/isExistingPath", async (t) => { |  | ||||||
|   t.afterEach(() => { |  | ||||||
|     fsMock.restore() |  | ||||||
|   }) |  | ||||||
|  |  | ||||||
|   await t.test("should return true if the file exists", async () => { |  | ||||||
|     fsMock({ |  | ||||||
|       "/file.txt": "", |  | ||||||
|     }) |  | ||||||
|     assert.strictEqual(await isExistingPath("/file.txt"), true) |  | ||||||
|   }) |  | ||||||
|  |  | ||||||
|   await t.test("should return false if the file doesn't exists", async () => { |  | ||||||
|     fsMock({ |  | ||||||
|       "/file.txt": "", |  | ||||||
|     }) |  | ||||||
|     assert.strictEqual(await isExistingPath("/randomfile.txt"), false) |  | ||||||
|   }) |  | ||||||
| }) |  | ||||||
| @@ -1,10 +0,0 @@ | |||||||
| import fs from "node:fs" |  | ||||||
|  |  | ||||||
| export const isExistingPath = async (path: string): Promise<boolean> => { |  | ||||||
|   try { |  | ||||||
|     await fs.promises.access(path, fs.constants.F_OK) |  | ||||||
|     return true |  | ||||||
|   } catch { |  | ||||||
|     return false |  | ||||||
|   } |  | ||||||
| } |  | ||||||
							
								
								
									
										46
									
								
								src/validateHTML.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								src/validateHTML.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | |||||||
|  | export interface ValidateHTMLOptions { | ||||||
|  |   htmlData: string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export interface ValidationMessage { | ||||||
|  |   type: "error" | "info" | "non-document-error" | ||||||
|  |   subType?: "warning" | "fatal" | "internal" | "io" | "schema" | ||||||
|  |   message: string | ||||||
|  |   extract?: string | ||||||
|  |   lastLine: number | ||||||
|  |   firstColumn: number | ||||||
|  |   lastColumn: number | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export interface ValidateHTMLResult { | ||||||
|  |   messages: ValidationMessage[] | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export const validateHTML = async ( | ||||||
|  |   options: ValidateHTMLOptions, | ||||||
|  | ): Promise<ValidateHTMLResult> => { | ||||||
|  |   const { htmlData } = options | ||||||
|  |   const url = new URL("https://validator.w3.org/nu/") | ||||||
|  |   url.searchParams.set("out", "json") | ||||||
|  |   const response = await fetch(url, { | ||||||
|  |     method: "POST", | ||||||
|  |     body: htmlData, | ||||||
|  |     headers: { | ||||||
|  |       "Content-Type": "text/html", | ||||||
|  |     }, | ||||||
|  |   }) | ||||||
|  |   if (!response.ok) { | ||||||
|  |     throw new Error(`Failed to validate HTML`) | ||||||
|  |   } | ||||||
|  |   const result = (await response.json()) as ValidateHTMLResult | ||||||
|  |   return result | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export const getHTMLFromURL = async (url: string): Promise<string> => { | ||||||
|  |   const response = await fetch(url) | ||||||
|  |   if (!response.ok) { | ||||||
|  |     throw new Error(`Failed to fetch HTML from "${url}"`) | ||||||
|  |   } | ||||||
|  |   const html = await response.text() | ||||||
|  |   return html | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user