Skip to content

Commit 1ccca7e

Browse files
author
Shinigami
authored
chore: modernize code / no-var (#394)
* chore: add lint rule no-var * chore: apply lint rule no-var * chore: add lint rule prefer-const * chore: apply lint rule prefer-const * chore: improve eslint-disable * chore: use const * chore: lint bin/htmlhint
1 parent 7b63cb2 commit 1ccca7e

Some content is hidden

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

52 files changed

+455
-452
lines changed

.eslintrc.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ module.exports = {
1414
'arrow-body-style': ['error'],
1515
'no-template-curly-in-string': 'error',
1616
'no-useless-concat': 'error',
17+
'no-var': 'error',
1718
'one-var': ['error', 'never'],
1819
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
20+
'prefer-const': 'error',
1921
'prefer-template': 'error',
2022
quotes: ['error', 'single', { avoidEscape: true }],
2123
'template-curly-spacing': 'error',

bin/formatter.js

+14-16
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,42 @@
1-
var path = require('path')
2-
var events = require('events')
3-
var glob = require('glob')
1+
const path = require('path')
2+
const events = require('events')
3+
const glob = require('glob')
44
path.parse = path.parse || require('path-parse')
55

6-
var mapFormatters
7-
var arrSupportedFormatters
8-
var HTMLHint
9-
var options
6+
let HTMLHint
7+
let options
108

119
// load formatters
12-
mapFormatters = loadFormatters()
13-
arrSupportedFormatters = []
10+
const mapFormatters = loadFormatters()
11+
const arrSupportedFormatters = []
1412

15-
for (var formatterName in mapFormatters) {
13+
for (const formatterName in mapFormatters) {
1614
if (formatterName !== 'default') {
1715
arrSupportedFormatters.push(formatterName)
1816
}
1917
}
2018

2119
// load all formatters
2220
function loadFormatters() {
23-
var arrFiles = glob.sync('./formatters/*.js', {
21+
const arrFiles = glob.sync('./formatters/*.js', {
2422
cwd: __dirname,
2523
dot: false,
2624
nodir: true,
2725
strict: false,
2826
silent: true,
2927
})
3028

31-
var mapFormatters = {}
29+
const mapFormatters = {}
3230
arrFiles.forEach((file) => {
33-
var fileInfo = path.parse(file)
34-
var formatterPath = path.resolve(__dirname, file)
31+
const fileInfo = path.parse(file)
32+
const formatterPath = path.resolve(__dirname, file)
3533
mapFormatters[fileInfo.name] = require(formatterPath)
3634
})
3735

3836
return mapFormatters
3937
}
4038

41-
var formatter = new events.EventEmitter()
39+
const formatter = new events.EventEmitter()
4240

4341
formatter.getSupported = function () {
4442
return arrSupportedFormatters
@@ -50,7 +48,7 @@ formatter.init = function (tmpHTMLHint, tmpOptions) {
5048
}
5149

5250
formatter.setFormat = function (format) {
53-
var formatHandel = mapFormatters[format]
51+
const formatHandel = mapFormatters[format]
5452

5553
if (formatHandel === undefined) {
5654
console.log(

bin/formatters/checkstyle.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var xml = require('xml')
1+
const xml = require('xml')
22

3-
var checkstyleFormatter = function (formatter) {
3+
const checkstyleFormatter = function (formatter) {
44
formatter.on('end', (event) => {
5-
var arrFiles = []
6-
var arrAllMessages = event.arrAllMessages
5+
const arrFiles = []
6+
const arrAllMessages = event.arrAllMessages
77

88
arrAllMessages.forEach((fileInfo) => {
9-
var arrMessages = fileInfo.messages
10-
var arrErrors = []
9+
const arrMessages = fileInfo.messages
10+
const arrErrors = []
1111

1212
arrMessages.forEach((message) => {
1313
arrErrors.push({
@@ -34,7 +34,7 @@ var checkstyleFormatter = function (formatter) {
3434
})
3535
})
3636

37-
var objXml = {
37+
const objXml = {
3838
checkstyle: [
3939
{
4040
_attr: {

bin/formatters/compact.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var compactFormatter = function (formatter, HTMLHint, options) {
2-
var nocolor = options.nocolor
1+
const compactFormatter = function (formatter, HTMLHint, options) {
2+
const nocolor = options.nocolor
33

44
formatter.on('file', (event) => {
55
event.messages.forEach((message) => {
@@ -16,10 +16,10 @@ var compactFormatter = function (formatter, HTMLHint, options) {
1616
})
1717

1818
formatter.on('end', (event) => {
19-
var allHintCount = event.allHintCount
19+
const allHintCount = event.allHintCount
2020
if (allHintCount > 0) {
2121
console.log('')
22-
var message = '%d problems'
22+
const message = '%d problems'
2323
console.log(nocolor ? message : message.red, event.allHintCount)
2424
}
2525
})

bin/formatters/default.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
var defaultFormatter = function (formatter, HTMLHint, options) {
2-
var nocolor = options.nocolor
1+
const defaultFormatter = function (formatter, HTMLHint, options) {
2+
const nocolor = options.nocolor
33

44
formatter.on('start', () => {
55
console.log('')
66
})
77

88
formatter.on('config', (event) => {
9-
var configPath = event.configPath
9+
const configPath = event.configPath
1010
console.log(' Config loaded: %s', nocolor ? configPath : configPath.cyan)
1111
console.log('')
1212
})
1313

1414
formatter.on('file', (event) => {
1515
console.log(` ${event.file.white}`)
1616

17-
var arrLogs = HTMLHint.format(event.messages, {
17+
const arrLogs = HTMLHint.format(event.messages, {
1818
colors: nocolor ? false : true,
1919
indent: 6,
2020
})
@@ -27,11 +27,11 @@ var defaultFormatter = function (formatter, HTMLHint, options) {
2727
})
2828

2929
formatter.on('end', (event) => {
30-
var allFileCount = event.allFileCount
31-
var allHintCount = event.allHintCount
32-
var allHintFileCount = event.allHintFileCount
33-
var time = event.time
34-
var message
30+
const allFileCount = event.allFileCount
31+
const allHintCount = event.allHintCount
32+
const allHintFileCount = event.allHintFileCount
33+
const time = event.time
34+
let message
3535

3636
if (allHintCount > 0) {
3737
message = 'Scanned %d files, found %d errors in %d files (%d ms)'

bin/formatters/html.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var fs = require('fs')
1+
const fs = require('fs')
22

3-
var htmlFormatter = function (formatter) {
3+
const htmlFormatter = function (formatter) {
44
formatter.on('end', (event) => {
5-
var fileContent
5+
let fileContent
66
fileContent = '<html>'
77
fileContent += '<head><title>HTML Hint Violation Report</title></head>'
88
fileContent += '<body>'
@@ -12,9 +12,9 @@ var htmlFormatter = function (formatter) {
1212
fileContent +=
1313
'<tr><th>Number#</th><th>File Name</th><th>Line Number</th><th>Message</th></tr>'
1414

15-
var arrAllMessages = event.arrAllMessages
15+
const arrAllMessages = event.arrAllMessages
1616
arrAllMessages.forEach((fileInfo) => {
17-
var arrMessages = fileInfo.messages
17+
const arrMessages = fileInfo.messages
1818
arrMessages.forEach((message, i) => {
1919
fileContent = `${fileContent}<tr><td>${i + 1}</td><td>${
2020
fileInfo.file

bin/formatters/json.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var jsonFormatter = function (formatter) {
1+
const jsonFormatter = function (formatter) {
22
formatter.on('end', (event) => {
33
console.log(JSON.stringify(event.arrAllMessages))
44
})

bin/formatters/junit.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
var xml = require('xml')
1+
const xml = require('xml')
22

3-
var junitFormatter = function (formatter, HTMLHint) {
3+
const junitFormatter = function (formatter, HTMLHint) {
44
formatter.on('end', (event) => {
5-
var arrTestcase = []
6-
var arrAllMessages = event.arrAllMessages
5+
const arrTestcase = []
6+
const arrAllMessages = event.arrAllMessages
77

88
arrAllMessages.forEach((fileInfo) => {
9-
var arrMessages = fileInfo.messages
10-
var arrLogs = HTMLHint.format(arrMessages)
9+
const arrMessages = fileInfo.messages
10+
const arrLogs = HTMLHint.format(arrMessages)
1111

1212
arrTestcase.push({
1313
testcase: [
@@ -29,7 +29,7 @@ var junitFormatter = function (formatter, HTMLHint) {
2929
})
3030
})
3131

32-
var objXml = {
32+
const objXml = {
3333
testsuites: [
3434
{
3535
testsuite: [

bin/formatters/markdown.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
var markdownFormatter = function (formatter, HTMLHint) {
1+
const markdownFormatter = function (formatter, HTMLHint) {
22
formatter.on('end', (event) => {
33
console.log('# TOC')
44

5-
var arrToc = []
6-
var arrContents = []
7-
var arrAllMessages = event.arrAllMessages
5+
const arrToc = []
6+
const arrContents = []
7+
const arrAllMessages = event.arrAllMessages
88

99
arrAllMessages.forEach((fileInfo) => {
10-
var filePath = fileInfo.file
11-
var arrMessages = fileInfo.messages
12-
var errorCount = 0
13-
var warningCount = 0
10+
const filePath = fileInfo.file
11+
const arrMessages = fileInfo.messages
12+
let errorCount = 0
13+
let warningCount = 0
1414

1515
arrMessages.forEach((message) => {
1616
if (message.type === 'error') {
@@ -26,7 +26,7 @@ var markdownFormatter = function (formatter, HTMLHint) {
2626
arrContents.push('')
2727
arrContents.push(`Found ${errorCount} errors, ${warningCount} warnings`)
2828

29-
var arrLogs = HTMLHint.format(arrMessages)
29+
const arrLogs = HTMLHint.format(arrMessages)
3030
arrContents.push('')
3131
arrLogs.forEach((log) => {
3232
arrContents.push(` ${log}`)

bin/formatters/unix.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var unixFormatter = function (formatter, HTMLHint, options) {
2-
var nocolor = options.nocolor
1+
const unixFormatter = function (formatter, HTMLHint, options) {
2+
const nocolor = options.nocolor
33
formatter.on('file', (event) => {
44
event.messages.forEach((message) => {
55
console.log(
@@ -14,10 +14,10 @@ var unixFormatter = function (formatter, HTMLHint, options) {
1414
})
1515

1616
formatter.on('end', (event) => {
17-
var allHintCount = event.allHintCount
17+
const allHintCount = event.allHintCount
1818
if (allHintCount > 0) {
1919
console.log('')
20-
var message = '%d problems'
20+
const message = '%d problems'
2121
console.log(nocolor ? message : message.red, event.allHintCount)
2222
}
2323
})

0 commit comments

Comments
 (0)