Skip to content

fix: add prettier and eslint #388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
env: {
browser: true,
amd: true,
node: true,
mocha: true,
},
parserOptions: {
ecmaVersion: 6,
sourceType: 'module',
},
}
18 changes: 10 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
Expand All @@ -21,15 +21,17 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
1 change: 0 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Run lint
run: npm run lint

- name: Build
run: npm run build --if-present
env:
Expand Down
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
/coverage

# production
/lib
/dist

# npm
package-lock.json
npm-debug.log*
.nyc_output
test/html
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'm a fan of semicolons because it increases readability

Do you have an argument why you want to disable semis?

"singleQuote": true,
"bracketSpacing": true,
"trailingComma": "es5",
"useTabs": false,
"tabWidth": 2,
"printWidth": 80
}
6 changes: 0 additions & 6 deletions .prettierrc.json

This file was deleted.

7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
HTMLHint change log
====================
# HTMLHint change log

## ver 0.9.14 (2016-5-2)

Expand Down Expand Up @@ -57,7 +56,7 @@ fix:

1. close issue: #79, fix exit with 0 when hint errors
2. fix end event col
2. attr-unsafe-chars(rule): exclude `\r\n`
3. attr-unsafe-chars(rule): exclude `\r\n`

## ver 0.9.8 (2015-10-7)

Expand Down Expand Up @@ -129,7 +128,7 @@ add:

fix:

1. compatible with:
1. compatible with:

<div class="foo"
<div class"foo">
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
First, thank you for considering contributing to HTMLHint! It's people like you that make the open source community such a great community! 😊

We welcome any type of contribution, not only code. You can help with

- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
- **Marketing**: writing blog posts, howto's, printing stickers, ...
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
- **Code**: take a look at the [open issues](https://github.com/thedaviddias/HTMLHint/issues). Even if you can't write code, commenting on them, showing that you care about a given issue matters. It helps us triage them.

## Your First Contribution

Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
Working on your first Pull Request? You can learn how from this _free_ series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).

## Submitting code

Expand Down
98 changes: 50 additions & 48 deletions bin/formatter.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
var path = require('path');
var events = require('events');
var glob = require('glob');
path.parse = path.parse || require('path-parse');
var path = require('path')
var events = require('events')
var glob = require('glob')
path.parse = path.parse || require('path-parse')

var mapFormatters;
var arrSupportedFormatters;
var HTMLHint;
var options;
var mapFormatters
var arrSupportedFormatters
var HTMLHint
var options

// load formatters
mapFormatters = loadFormatters();
arrSupportedFormatters = [];
for(var formatterName in mapFormatters){
if(formatterName !== 'default'){
arrSupportedFormatters.push(formatterName);
}
mapFormatters = loadFormatters()
arrSupportedFormatters = []
for (var formatterName in mapFormatters) {
if (formatterName !== 'default') {
arrSupportedFormatters.push(formatterName)
}
}

// load all formatters
function loadFormatters(){
var arrFiles = glob.sync('./formatters/*.js', {
'cwd': __dirname,
'dot': false,
'nodir': true,
'strict': false,
'silent': true
});
var mapFormatters = {};
arrFiles.forEach(function(file){
var fileInfo = path.parse(file);
var formatterPath = path.resolve(__dirname, file);
mapFormatters[fileInfo.name] = require(formatterPath);
});
return mapFormatters;
function loadFormatters() {
var arrFiles = glob.sync('./formatters/*.js', {
cwd: __dirname,
dot: false,
nodir: true,
strict: false,
silent: true,
})
var mapFormatters = {}
arrFiles.forEach(function (file) {
var fileInfo = path.parse(file)
var formatterPath = path.resolve(__dirname, file)
mapFormatters[fileInfo.name] = require(formatterPath)
})
return mapFormatters
}

var formatter =new events.EventEmitter();
formatter.getSupported = function(){
return arrSupportedFormatters;
};
formatter.init = function(tmpHTMLHint, tmpOptions){
HTMLHint = tmpHTMLHint;
options = tmpOptions;
};
formatter.setFormat = function(format){
var formatHandel = mapFormatters[format];
if(formatHandel === undefined){
console.log('No supported formatter, supported formatters: %s'.red, arrSupportedFormatters.join(', '));
process.exit(1);
}
else{
formatHandel(formatter, HTMLHint, options);
}
};
var formatter = new events.EventEmitter()
formatter.getSupported = function () {
return arrSupportedFormatters
}
formatter.init = function (tmpHTMLHint, tmpOptions) {
HTMLHint = tmpHTMLHint
options = tmpOptions
}
formatter.setFormat = function (format) {
var formatHandel = mapFormatters[format]
if (formatHandel === undefined) {
console.log(
'No supported formatter, supported formatters: %s'.red,
arrSupportedFormatters.join(', ')
)
process.exit(1)
} else {
formatHandel(formatter, HTMLHint, options)
}
}

module.exports = formatter;
module.exports = formatter
96 changes: 49 additions & 47 deletions bin/formatters/checkstyle.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
var xml = require('xml');
var xml = require('xml')

var checkstyleFormatter = function(formatter){
formatter.on('end', function(event){
var arrFiles = [];
var arrAllMessages = event.arrAllMessages;
arrAllMessages.forEach(function(fileInfo){
var arrMessages = fileInfo.messages;
var arrErrors = [];
arrMessages.forEach(function(message){
arrErrors.push({
error: {
_attr: {
line: message.line,
column: message.col,
severity: message.type,
message: message.message,
source: 'htmlhint.'+message.rule.id
}
}
});
});
arrFiles.push({
file: [
{
_attr: {
name: fileInfo.file
}
}
].concat(arrErrors)
});
});
var objXml = {
checkstyle: [
{
_attr: {
version: '4.3'
}
}
].concat(arrFiles)
};
console.log(xml(objXml, {
declaration: true,
indent: ' '
}));
});
};
module.exports = checkstyleFormatter;
var checkstyleFormatter = function (formatter) {
formatter.on('end', function (event) {
var arrFiles = []
var arrAllMessages = event.arrAllMessages
arrAllMessages.forEach(function (fileInfo) {
var arrMessages = fileInfo.messages
var arrErrors = []
arrMessages.forEach(function (message) {
arrErrors.push({
error: {
_attr: {
line: message.line,
column: message.col,
severity: message.type,
message: message.message,
source: 'htmlhint.' + message.rule.id,
},
},
})
})
arrFiles.push({
file: [
{
_attr: {
name: fileInfo.file,
},
},
].concat(arrErrors),
})
})
var objXml = {
checkstyle: [
{
_attr: {
version: '4.3',
},
},
].concat(arrFiles),
}
console.log(
xml(objXml, {
declaration: true,
indent: ' ',
})
)
})
}
module.exports = checkstyleFormatter
49 changes: 25 additions & 24 deletions bin/formatters/compact.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
var compactFormatter = function(formatter, HTMLHint, options){
var nocolor = options.nocolor;
formatter.on('file', function(event){
event.messages.forEach(function (message) {
console.log('%s: line %d, col %d, %s - %s (%s)',
event.file,
message.line,
message.col,
message.type,
message.message,
message.rule.id
);
});
});
formatter.on('end', function(event){
var allHintCount = event.allHintCount;
if(allHintCount > 0){
console.log('');
var message = '%d problems';
console.log(nocolor ? message : message.red, event.allHintCount);
}
});
};
module.exports = compactFormatter;
var compactFormatter = function (formatter, HTMLHint, options) {
var nocolor = options.nocolor
formatter.on('file', function (event) {
event.messages.forEach(function (message) {
console.log(
'%s: line %d, col %d, %s - %s (%s)',
event.file,
message.line,
message.col,
message.type,
message.message,
message.rule.id
)
})
})
formatter.on('end', function (event) {
var allHintCount = event.allHintCount
if (allHintCount > 0) {
console.log('')
var message = '%d problems'
console.log(nocolor ? message : message.red, event.allHintCount)
}
})
}
module.exports = compactFormatter
Loading