# @htmllinter/core

> html linter based on posthtml. shareable and plug-able linter made on top of posthtml

Latest version **0.5.1** (published 2020-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @htmllinter/core
pnpm add @htmllinter/core
yarn add @htmllinter/core
bun add @htmllinter/core
```

Provides the command `htmllinter`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.1 |
| Published | 2020-05-24 |
| First published | 2020-02-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 105.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | anikethsaha |
| Maintainers | anixsaha |
| Keywords | html, lint, linter, posthtml, plugins, htmllinter |

## Links

- npm: https://www.npmjs.com/package/@htmllinter/core
- Repository: https://github.com/anikethsaha/htmllinter
- Homepage: https://github.com/anikethsaha/htmllinter#readme
- Issues: https://github.com/anikethsaha/htmllinter/issues
- npm.io page: https://npm.io/package/@htmllinter/core

## Dependencies (7)

- [ajv](https://npm.io/package/ajv.md) ^6.12.2
- [glob](https://npm.io/package/glob.md) ^7.1.6
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [posthtml](https://npm.io/package/posthtml.md) ^0.13.0
- [strip-ansi](https://npm.io/package/strip-ansi.md) ^6.0.0
- [text-table](https://npm.io/package/text-table.md) ^0.2.0
- [reshape-parser](https://npm.io/package/reshape-parser.md) ^1.0.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 0.5.1 (latest) — 2020-05-24
- 0.5.0 — 2020-05-24
- 0.4.0 — 2020-05-09
- 0.3.0 — 2020-02-29
- 0.2.0 — 2020-02-28
- 0.0.1 — 2020-02-27

## README

<p align="center">
  
<h1 align="center"> htmllinter </h1>

<p align="center"> html linter based on posthtml. shareable and plug-able linter made on top of posthtml </p>

</p>

<p align="center">

<img alt="efba logo" src="https://imgur.com/9pWjH5N.png" width="350px" />

</p>

## Table of Contents

- [Installation](#installation)
  - [About the packages](#about-the-packages)
- [Usage](#usage)
- [CLI](#cli)
  - [Usage](#usage-1)
- [Node API](#node-api)
- [Config File](#config-file)
  - [1. `standard`](#1-config)
  - [2. `plugins`](#2-plugins)
  - [2. `rules`](#2-rules)
- [Rules](#rules)
- [Creating your own `rules` or `plugins`](#creating-your-own-rules-or-plugins)
- [Creating your own shareable `config`](#creating-your-own-shareable-config)
- [Contributing](#contributing)
- [Note](#note)
- [Inspiration/Thanks](#inspirationthanks)

## Installation

```shell
npm install @htmllinter/core @htmllinter/basic-config --save-dev
```

#### About the packages

- `@htmllinter/core` is the linter which comes with its own CLI to run with. It supports pretty error display in table format. It has node API which can be use to
  linter node programs.

- `@htmllinter/basic-config`: it is the shareable config package which uses `@htmllinter/basic-rules` package to load rules and share it. Read more about it [**HERE**](https://github.com/anikethsaha/htmllinter/blob/config-feat/packages/basic-config/README.md)

- `@htmllinter/basic-rules` : it is the rules package contains some basic rules. **You dont need to install it explicitly as it comes with `@htmllinter/basic-config`**

## Usage

`htmllinter` can be configured through a config file name `htmllinter.config.js` . Create this file in your project and follow [this guide](#config-file) to configure this file.

Add `@htmllinter/basic-config` in your `htmllinter.config.js` in `extend` property

`htmllinter.config.js`

```js

module.exports : {
  extend : require('@htmllinter/basic-config')
}

```

And now you are ready to lint your html files using the following commands

```shell
htmllinter input.html
```

in this command, if your `htmllinter.config.js` file is present at the directory from where this command is being run, then it will load that config file
and run the linter and check the `input.html` file. **If you dont have any `htmllinter.config.js` file preset at the root, it will load the linter with default config which is `{}`, an empty object.**

The input accepts a `glob` pattern, so it can be patterns like `**/*.html`, `*.html` etc.
You can find more about these patterns [**here**](https://github.com/isaacs/node-glob#glob-primer)

You can use the `--config` or `-c` flag in order to specify the path to your `htmllinter.config.js` file. like this

```shell
htmllinter input.html -c ./path/to/config/folder
```

> Note that the path passed the `-c` or `--config` must be to a directory instead of pointing to the config file.

> Also, it should be relative from the directory where `htmllinter` is being run

**Check the [CLI](#cli) Guide to know more about how to use the CLI and the option it takes**

## CLI

The CLI is one of the to run the `htmllinter`. It comes by default with `htmllitner` package so you dont need to install it seperately.

### Usage

```

Usage :

htmllinter <input> [Options]

input           - it is the input(html) file name, it accepts glob pattern.
                example :
                  - "input.html"
                  - "input"
                  - "/*.html"
                  - "."

Options
  -c, --config    - path to htmllinter.config.js.
                    default is "."
                    example :
                    - '.'
                    - './dir/'

Example

    htmllinter input.html
    htmllinter input -c ../
    htmllinter **/*

```

## Node API

**[REFER THIS](https://github.com/anikethsaha/htmllinter/blob/master/docs/api.md)**

## Config File

`htmllinter` can be configured through config file name `htmllinter.config.js`.

> Note, the file name has to be `htmllinter.config.js`

There are three properties this config file exports

### 1. `extend`

Type : `Object (modules)`
Default : `none`

This option extends the config which is passed here. A shareable config package is like an usual `htmllinter.config.js`. They exports properties like `plugins` , `rules` and they can even extend other config in `extend` property

`htmllinter.config.js`

```js
module.exports = {
  extend: require('@htmllinter/basic-config'),
};
```

**Learn more about creating your own [`shareable config rule packages here`]()**

### 2. `plugins`

Type : `Array<Objects>`
Default : `[]`

This accepts the array of plugins packages. This plugins are just packages exporting the rule defination and rule name. This rules are not turned on
by default, you need to turn them on in the [`rules`](#rules) property of the config file.

EXAMPLE

`htmllinter.config.js`

```js
module.exports = {
  plugins: [require('no-bool-true-explicit-define')],
};
```

And then you need to manually turn the rule on that is coming from the plugin ,(`no-bool-true-explicit-define` for this example)

```js
module.exports = {
  plugins: [require('no-bool-true-explicit-define')],
  rules: {
    'no-bool-true-explicit-define': 'on',
  },
};
```

**Learn more about creating a plugins [`here`](https://github.com/anikethsaha/htmllinter/blob/master/docs/how-to-create-plugin.md)**

**learn more about rules [`here`](#rules)**

### 2. `rules`

Type : `Objects`
Default : `{}`

This is the list of the rules and there actionable value like whether they are turned `on` or `off`

```js
module.exports = {
  plugins: [require('no-bool-true-explicit-define')],
  rules: {
    'no-bool-true-explicit-define': 'on',
    'no-empty-tag': 'off',
  },
};
```

## Rules

`@htmllinter/core` doesnt comes with any rules, it is recommended to use `@htmllinter/basic-standard` along with it in order to get the rules.

List of rules comes with [`@htmllinter/basic-rules`]()

- `no-empty-tag` : Read [**here**] for more info about this
- `no-duplicate-id` : Read [**here**] for more info about this
- `no-bool-true-explicit-define` : Read [**here**] for more info about this

## Creating your own `rules` or `plugins`

`plugins`/`rules` are nothing but a module which is exporting two things

- `ruleName` : `string`, as name suggests, it is the name of the rule

- `rule` : `function`, it is a function which takes three parameters (`options, reporter, repoterNode`) and returns a function which gets two parameters (`tree`,`result`)

**[CLICK HERE to read in details how to create a rule](https://github.com/anikethsaha/htmllinter/blob/master/docs/how-to-create-rule.md)**

## Creating your own shareable `config`

A shareable `config` is nothing by a module exporting a `htmllinter` config properties which consist of `plugins`, `rules` and `extend` (which in turn exports a config)

**[CLICK HERE to read in details how to create a shareable `config`](https://github.com/anikethsaha/htmllinter/blob/master/docs/how-to-shareable-config.md)**

## Contributing

Feel free to submit PR with new features, bug fixes, docs update and other changes you think needs to be done.
Also, submit an issue if you think needs to be corrected or implemented or needs a discussion

## Note

This is still an early stage linter with not so advance rules. Please contribute so that we can get it stable and ready for `v1`.

## Inspiration/Thanks

- A huge inspiration of this is `stylelint`.
- `posthtml` : as it is made on top of `posthtml` and it use the behavior of `posthtml`'s plugins

---
_Source: https://npm.io/package/@htmllinter/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
