Skip to content

Commit f0ad770

Browse files
authored
fix: add prettier and eslint (#388)
* add eslintrc * eslint and prettier all files * fix: replace by npm script * fix: prettify more files * fixes based on review
1 parent 9914725 commit f0ad770

File tree

97 files changed

+4042
-3246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4042
-3246
lines changed

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
3+
env: {
4+
browser: true,
5+
amd: true,
6+
node: true,
7+
mocha: true,
8+
},
9+
parserOptions: {
10+
ecmaVersion: 6,
11+
sourceType: 'module',
12+
},
13+
}

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
---
22
name: Bug report
33
about: Create a report to help us improve
4-
54
---
65

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

109
**To Reproduce**
1110
Steps to reproduce the behavior:
11+
1212
1. Go to '...'
1313
2. Click on '....'
1414
3. Scroll down to '....'
@@ -21,15 +21,17 @@ A clear and concise description of what you expected to happen.
2121
If applicable, add screenshots to help explain your problem.
2222

2323
**Desktop (please complete the following information):**
24-
- OS: [e.g. iOS]
25-
- Browser [e.g. chrome, safari]
26-
- Version [e.g. 22]
24+
25+
- OS: [e.g. iOS]
26+
- Browser [e.g. chrome, safari]
27+
- Version [e.g. 22]
2728

2829
**Smartphone (please complete the following information):**
29-
- Device: [e.g. iPhone6]
30-
- OS: [e.g. iOS8.1]
31-
- Browser [e.g. stock browser, safari]
32-
- Version [e.g. 22]
30+
31+
- Device: [e.g. iPhone6]
32+
- OS: [e.g. iOS8.1]
33+
- Browser [e.g. stock browser, safari]
34+
- Version [e.g. 22]
3335

3436
**Additional context**
3537
Add any other context about the problem here.

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
---
22
name: Feature request
33
about: Suggest an idea for this project
4-
54
---
65

76
**Is your feature request related to a problem? Please describe.**

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
- name: Install dependencies
3434
run: npm ci
3535

36+
- name: Run lint
37+
run: npm run lint
38+
3639
- name: Build
3740
run: npm run build --if-present
3841
env:

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
/coverage
88

99
# production
10-
/lib
10+
/dist
1111

1212
# npm
1313
package-lock.json
1414
npm-debug.log*
15+
.nyc_output
16+
test/html

.prettierrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"bracketSpacing": true,
5+
"trailingComma": "es5",
6+
"useTabs": false,
7+
"tabWidth": 2,
8+
"printWidth": 80
9+
}

.prettierrc.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
HTMLHint change log
2-
====================
1+
# HTMLHint change log
32

43
## ver 0.9.14 (2016-5-2)
54

@@ -57,7 +56,7 @@ fix:
5756

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

6261
## ver 0.9.8 (2015-10-7)
6362

@@ -129,7 +128,7 @@ add:
129128

130129
fix:
131130

132-
1. compatible with:
131+
1. compatible with:
133132

134133
<div class="foo"
135134
<div class"foo">

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
First, thank you for considering contributing to HTMLHint! It's people like you that make the open source community such a great community! 😊
66

77
We welcome any type of contribution, not only code. You can help with
8+
89
- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
910
- **Marketing**: writing blog posts, howto's, printing stickers, ...
1011
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
1112
- **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.
1213

1314
## Your First Contribution
1415

15-
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).
16+
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).
1617

1718
## Submitting code
1819

bin/formatter.js

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
var path = require('path');
2-
var events = require('events');
3-
var glob = require('glob');
4-
path.parse = path.parse || require('path-parse');
1+
var path = require('path')
2+
var events = require('events')
3+
var glob = require('glob')
4+
path.parse = path.parse || require('path-parse')
55

6-
var mapFormatters;
7-
var arrSupportedFormatters;
8-
var HTMLHint;
9-
var options;
6+
var mapFormatters
7+
var arrSupportedFormatters
8+
var HTMLHint
9+
var options
1010

1111
// load formatters
12-
mapFormatters = loadFormatters();
13-
arrSupportedFormatters = [];
14-
for(var formatterName in mapFormatters){
15-
if(formatterName !== 'default'){
16-
arrSupportedFormatters.push(formatterName);
17-
}
12+
mapFormatters = loadFormatters()
13+
arrSupportedFormatters = []
14+
for (var formatterName in mapFormatters) {
15+
if (formatterName !== 'default') {
16+
arrSupportedFormatters.push(formatterName)
17+
}
1818
}
1919

2020
// load all formatters
21-
function loadFormatters(){
22-
var arrFiles = glob.sync('./formatters/*.js', {
23-
'cwd': __dirname,
24-
'dot': false,
25-
'nodir': true,
26-
'strict': false,
27-
'silent': true
28-
});
29-
var mapFormatters = {};
30-
arrFiles.forEach(function(file){
31-
var fileInfo = path.parse(file);
32-
var formatterPath = path.resolve(__dirname, file);
33-
mapFormatters[fileInfo.name] = require(formatterPath);
34-
});
35-
return mapFormatters;
21+
function loadFormatters() {
22+
var arrFiles = glob.sync('./formatters/*.js', {
23+
cwd: __dirname,
24+
dot: false,
25+
nodir: true,
26+
strict: false,
27+
silent: true,
28+
})
29+
var mapFormatters = {}
30+
arrFiles.forEach(function (file) {
31+
var fileInfo = path.parse(file)
32+
var formatterPath = path.resolve(__dirname, file)
33+
mapFormatters[fileInfo.name] = require(formatterPath)
34+
})
35+
return mapFormatters
3636
}
3737

38-
var formatter =new events.EventEmitter();
39-
formatter.getSupported = function(){
40-
return arrSupportedFormatters;
41-
};
42-
formatter.init = function(tmpHTMLHint, tmpOptions){
43-
HTMLHint = tmpHTMLHint;
44-
options = tmpOptions;
45-
};
46-
formatter.setFormat = function(format){
47-
var formatHandel = mapFormatters[format];
48-
if(formatHandel === undefined){
49-
console.log('No supported formatter, supported formatters: %s'.red, arrSupportedFormatters.join(', '));
50-
process.exit(1);
51-
}
52-
else{
53-
formatHandel(formatter, HTMLHint, options);
54-
}
55-
};
38+
var formatter = new events.EventEmitter()
39+
formatter.getSupported = function () {
40+
return arrSupportedFormatters
41+
}
42+
formatter.init = function (tmpHTMLHint, tmpOptions) {
43+
HTMLHint = tmpHTMLHint
44+
options = tmpOptions
45+
}
46+
formatter.setFormat = function (format) {
47+
var formatHandel = mapFormatters[format]
48+
if (formatHandel === undefined) {
49+
console.log(
50+
'No supported formatter, supported formatters: %s'.red,
51+
arrSupportedFormatters.join(', ')
52+
)
53+
process.exit(1)
54+
} else {
55+
formatHandel(formatter, HTMLHint, options)
56+
}
57+
}
5658

57-
module.exports = formatter;
59+
module.exports = formatter

bin/formatters/checkstyle.js

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,50 @@
1-
var xml = require('xml');
1+
var xml = require('xml')
22

3-
var checkstyleFormatter = function(formatter){
4-
formatter.on('end', function(event){
5-
var arrFiles = [];
6-
var arrAllMessages = event.arrAllMessages;
7-
arrAllMessages.forEach(function(fileInfo){
8-
var arrMessages = fileInfo.messages;
9-
var arrErrors = [];
10-
arrMessages.forEach(function(message){
11-
arrErrors.push({
12-
error: {
13-
_attr: {
14-
line: message.line,
15-
column: message.col,
16-
severity: message.type,
17-
message: message.message,
18-
source: 'htmlhint.'+message.rule.id
19-
}
20-
}
21-
});
22-
});
23-
arrFiles.push({
24-
file: [
25-
{
26-
_attr: {
27-
name: fileInfo.file
28-
}
29-
}
30-
].concat(arrErrors)
31-
});
32-
});
33-
var objXml = {
34-
checkstyle: [
35-
{
36-
_attr: {
37-
version: '4.3'
38-
}
39-
}
40-
].concat(arrFiles)
41-
};
42-
console.log(xml(objXml, {
43-
declaration: true,
44-
indent: ' '
45-
}));
46-
});
47-
};
48-
module.exports = checkstyleFormatter;
3+
var checkstyleFormatter = function (formatter) {
4+
formatter.on('end', function (event) {
5+
var arrFiles = []
6+
var arrAllMessages = event.arrAllMessages
7+
arrAllMessages.forEach(function (fileInfo) {
8+
var arrMessages = fileInfo.messages
9+
var arrErrors = []
10+
arrMessages.forEach(function (message) {
11+
arrErrors.push({
12+
error: {
13+
_attr: {
14+
line: message.line,
15+
column: message.col,
16+
severity: message.type,
17+
message: message.message,
18+
source: 'htmlhint.' + message.rule.id,
19+
},
20+
},
21+
})
22+
})
23+
arrFiles.push({
24+
file: [
25+
{
26+
_attr: {
27+
name: fileInfo.file,
28+
},
29+
},
30+
].concat(arrErrors),
31+
})
32+
})
33+
var objXml = {
34+
checkstyle: [
35+
{
36+
_attr: {
37+
version: '4.3',
38+
},
39+
},
40+
].concat(arrFiles),
41+
}
42+
console.log(
43+
xml(objXml, {
44+
declaration: true,
45+
indent: ' ',
46+
})
47+
)
48+
})
49+
}
50+
module.exports = checkstyleFormatter

bin/formatters/compact.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
var compactFormatter = function(formatter, HTMLHint, options){
2-
var nocolor = options.nocolor;
3-
formatter.on('file', function(event){
4-
event.messages.forEach(function (message) {
5-
console.log('%s: line %d, col %d, %s - %s (%s)',
6-
event.file,
7-
message.line,
8-
message.col,
9-
message.type,
10-
message.message,
11-
message.rule.id
12-
);
13-
});
14-
});
15-
formatter.on('end', function(event){
16-
var allHintCount = event.allHintCount;
17-
if(allHintCount > 0){
18-
console.log('');
19-
var message = '%d problems';
20-
console.log(nocolor ? message : message.red, event.allHintCount);
21-
}
22-
});
23-
};
24-
module.exports = compactFormatter;
1+
var compactFormatter = function (formatter, HTMLHint, options) {
2+
var nocolor = options.nocolor
3+
formatter.on('file', function (event) {
4+
event.messages.forEach(function (message) {
5+
console.log(
6+
'%s: line %d, col %d, %s - %s (%s)',
7+
event.file,
8+
message.line,
9+
message.col,
10+
message.type,
11+
message.message,
12+
message.rule.id
13+
)
14+
})
15+
})
16+
formatter.on('end', function (event) {
17+
var allHintCount = event.allHintCount
18+
if (allHintCount > 0) {
19+
console.log('')
20+
var message = '%d problems'
21+
console.log(nocolor ? message : message.red, event.allHintCount)
22+
}
23+
})
24+
}
25+
module.exports = compactFormatter

0 commit comments

Comments
 (0)