Skip to content

Commit

Permalink
Add project files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexesprit committed Aug 13, 2020
1 parent 7b904ee commit 0a96aea
Show file tree
Hide file tree
Showing 8 changed files with 1,272 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[{*.json,*.yml,*.yaml}]
indent_size = 2
indent_style = space
17 changes: 17 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint
on:
push:
branches: [master]
pull_request:
types: [opened, synchronize]
jobs:
lint:
name: Run ESLint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm install
- run: npm run lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Alexey

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# gulp-html-validate

Validate files with `html-validate`.

## Installation

```sh
> npm install --save-dev gulp-html-validate
```

## Usage

```js
const gulp = require('gulp');
const htmlvalidate = require('gulp-html-validate');

exports.default = () => gulp.src('index.html').pipe(htmlvalidate());
```

You can also pass options to the `htmlvalidate` function:

```js
exports.default = () =>
gulp.src('index.html').pipe(
htmlvalidate({
/* Your options here */
})
);
```

### Options

#### format

Any formatter supported by `html-validate` (`stylish` by default).

Type: `string`.

## License

Licensed under the [MIT License](./LICENSE).
45 changes: 45 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const through = require('through2');
const PluginError = require('plugin-error');

const { HtmlValidate } = require('html-validate');
const { getFormatter } = require('html-validate/build/cli/formatter');

const pluginName = 'gulp-html-validate';
const defaultOptions = {
format: 'stylish',
};

module.exports = (options) => {
const pluginOptions = options || defaultOptions;

const htmlvalidate = new HtmlValidate();
const formatter = getFormatter(pluginOptions.format);

return through.obj(function(file, encoding, callback) {
if (file.isNull()) {
callback(null, file);
return;
}

if (file.isStream()) {
callback(new PluginError(pluginName, 'Streaming not supported'));
return;
}

const result = htmlvalidate.validateFile(file.path);

if (!result.valid) {
const resultOutput = formatter(result);

this.emit(
'error',
new PluginError(pluginName, resultOutput, {
fileName: file.path,
showStack: false,
})
);
}

callback(null, file);
});
};
Loading

0 comments on commit 0a96aea

Please sign in to comment.