All Projects → angelikatyborska → vnu-elixir

angelikatyborska / vnu-elixir

Licence: MIT license
An Elixir client for the Nu HTML Checker (v.Nu).

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to vnu-elixir

vue-cli-template-library
Template for developing open-source vue.js libraries with Rollup + Jest + Babel + Storybook + TravisCI + SemanticRelease
Stars: ✭ 61 (+22%)
Mutual labels:  linter
linter-terraform-syntax
terraform validate linter and formatter for atom
Stars: ✭ 19 (-62%)
Mutual labels:  linter
codeclimate-apexmetrics
ApexMetrics - Code Climate engine for Salesforce [DISCONTINUED use CC PMD instead)
Stars: ✭ 46 (-8%)
Mutual labels:  linter
repolint
Tool to check github user/organization repositories for some simple and common issues.
Stars: ✭ 19 (-62%)
Mutual labels:  linter
prlint
GitHub App for linting pull request meta data
Stars: ✭ 122 (+144%)
Mutual labels:  linter
flexlint
A flexible linter with rules defined by regular expression
Stars: ✭ 19 (-62%)
Mutual labels:  linter
elm-lint
elm-lint lints Elm source code, to add additional guarantees to your project.
Stars: ✭ 27 (-46%)
Mutual labels:  linter
Frontend-StarterKit
Frontend StarterKit - [Gulp 4, Pug, SCSS, ES6+]
Stars: ✭ 13 (-74%)
Mutual labels:  linter
nimfmt
Nim code formatter / linter / style checker
Stars: ✭ 75 (+50%)
Mutual labels:  linter
actionlint
Static checker for GitHub Actions workflow files
Stars: ✭ 1,385 (+2670%)
Mutual labels:  linter
vscode-linter
Extension for code linting, all in one package. New linters can be easily added through an extension framework.
Stars: ✭ 47 (-6%)
Mutual labels:  linter
nano-staged
Tiny tool to run commands for modified, staged, and committed files in a GIT repository.
Stars: ✭ 347 (+594%)
Mutual labels:  linter
healthier
🧘‍♀️ Healthier is an opinionated style agnostic code linter – a friendly companion to Prettier
Stars: ✭ 78 (+56%)
Mutual labels:  linter
Husky.Net
Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
Stars: ✭ 394 (+688%)
Mutual labels:  linter
sqlclosecheck
Linter that confirms that DB rows and stats are closed properly.
Stars: ✭ 21 (-58%)
Mutual labels:  linter
f2e-spec
Alibaba Front-end Coding Guidelines and Relevant Tools
Stars: ✭ 548 (+996%)
Mutual labels:  linter
flake8-spellcheck
❄️ Spellcheck variables, classnames, comments, docstrings etc
Stars: ✭ 71 (+42%)
Mutual labels:  linter
gulp-html
Gulp plugin for HTML validation, using the official Nu Html Checker (v.Nu)
Stars: ✭ 70 (+40%)
Mutual labels:  html-validation
errchkjson
Go linter that checks types that are json encoded - reports unsupported types and unnecessary error checks
Stars: ✭ 29 (-42%)
Mutual labels:  linter
retext-assuming
Check for unhelpful ‘assuming’ phrases such as ‘just’, ‘simply’ or ‘obviously’ with retext
Stars: ✭ 15 (-70%)
Mutual labels:  linter

Vnu

angelikatyborska Hex.pm Hex.pm Hex.pm Coverage Status

An Elixir client for the Nu HTML Checker (v.Nu).

v.Nu is a document validity checker used by the W3C. It offers validating HTML, CSS, and SVG documents.

This library brings that functionality to Elixir by using the Checker's JSON API. It offers ExUnit assertions for validating dynamic content in tests, Mix tasks for validating static content, and general purpose functions to fulfill other needs.

Prerequisites

While it is possible to use this library with the service run by W3C at validator.w3.org/nu, I would recommend running your own instance. You will eliminate a lot of network latency if it runs on the same machine as your code, and you will not hit any rate limits that might exist for validator.w3.org/nu.

The source of the Checker can be found in the repository validator/validator. Follow their instructions on how to download it and run it as a web server.

The easiest option is to use the Docker image, like this:

docker run -it --rm -p 8888:8888 ghcr.io/validator/validator:latest

Check if the server is running:

$ curl localhost:8888 -I
HTTP/1.1 200 OK

Installation

Make sure to read about the prerequisites first.

Add Vnu as a dependency to your project's mix.exs. To use the built-in, Hackney-based HTTP client adapter, add :hackney too:

defp deps do
  [
    {:vnu, "~> 1.1", only: [:dev, :test], runtime: false},
    {:hackney, "~> 1.17"}
  ]
end

And run:

$ mix deps.get

Documentation

Available on hexdocs.pm.

Usage

ExUnit assertions

If you are building an application that generates HTML, CSS, or SVG files, you might want to use those validations in your tests.

  • Vnu.Assertions.assert_valid_html/2
  • Vnu.Assertions.assert_valid_css/2
  • Vnu.Assertions.assert_valid_svg/2

Phoenix controller test example

defmodule PhoenixAppWeb.PageControllerTest do
  use PhoenixAppWeb.ConnCase
  import Vnu.Assertions

    test "GET /", %{conn: conn} do
      vnu_opts = %{server_url: "http://localhost:8888", fail_on_warnings: true}
      conn = get(conn, "/")
      
      html_response =
        conn
        |> get("/")
        |> html_response(200)
        |> assert_valid_html(vnu_opts)
      
      assert html_response =~ "Welcome to Phoenix!"
    end
end

See examples/1_phoenix_app/test/phoenix_app_web/controllers/page_controller_test.exs for more.

Mix task

If you have static HTML, CSS, or SVG files in your project, you might want to validate them with those mix tasks:

  • mix vnu.validate.html
  • mix vnu.validate.css
  • mix vnu.validate.svg

Example

$ mix vnu.validate.css --server-url localhost:8888 assets/**/*.css

General purpose

If you need HTML, CSS, or SVG validation for something else, try one of those functions:

  • Vnu.validate_html/2
  • Vnu.validate_css/2
  • Vnu.validate_svg/2
iex> {:ok, result} = Vnu.validate_html("<!DOCTYPE html><html><head></head></html>",
  server_url: "http://localhost:8888")
{:ok,
 %Vnu.Result{
   messages: [
     %Vnu.Message{
       extract: "tml><head></head></html",
       first_column: 28,
       first_line: 1,
       hilite_length: 7,
       hilite_start: 10,
       last_column: 34,
       last_line: 1,
       message: "Element “head” is missing a required instance of child element “title”.",
       offset: nil,
       sub_type: nil,
       type: :error
     },
     %Vnu.Message{
       extract: "TYPE html><html><head>",
       first_column: 16,
       first_line: 1,
       hilite_length: 6,
       hilite_start: 10,
       last_column: 21,
       last_line: 1,
       message: "Consider adding a “lang” attribute to the “html” start tag to declare the language of this document.",
       offset: nil,
       sub_type: :warning,
       type: :info
     }
   ]
 }}

iex> Vnu.valid?(result)
false

Development

Make sure to read about the prerequisites first.

After cloning the repository, run mix deps.get and you should be ready for development.

To ensure code consistency, run mix format, mix credo, and mix dialyzer.

Running tests

All test that expect to talk with the server accept the server's URL as an VNU_SERVER_URL environment variable or fallback to the default http://localhost:8888.

$ VNU_SERVER_URL=http://localhost:4000/ mix test 

If you're adding a new test, make sure it will do that do.

Contributing

Issues

If you noticed a problem with the library or its documentation, or have an idea for a feature, open an issue.

If you have an idea on how to act upon the problem or idea, feel free to open a pull request instead.

Pull requests

If you noticed a problem with the library or its documentation and know how to fix it, or have an idea for a feature, or want to fix a typo, open a pull request.

If you are not sure of your changes or need help finishing them, open a pull request anyway. I'll try to help!

License

Vnu is released under the MIT License. See the LICENSE file for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].