Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 39d9f93

Browse files
committedApr 24, 2020
Merge branch 'release/0.4.0'
2 parents 5cdf09e + e66a09e commit 39d9f93

File tree

7 files changed

+528
-408
lines changed

7 files changed

+528
-408
lines changed
 

‎.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
language: node_js
22
node_js:
3-
- '8'
43
- '10'
4+
- '12'
55
cache:
66
yarn: true
77
script:
88
- yarn run lint
99
notifications:
1010
slack:
1111
secure: k8qoq+byM+x9fTlLeaz2TRb+EYvwWlaYjkY0fp87RnWEbLeYjj4mumcwFJclNtocdgKbxG4LDV7BrDsu4Mbsp2YFpQ8WU6e6+xTrLTrLDrlsFQ6St1KX7TDymZ+wkSTyLvSECNkdcNt0dek8mWrT6HWZ/v/4HzWjjl6x7EOjPJ8Hnf4fesrfS5en1IMXDbK3Z/HrxMXNZCV3/k5ktZ3Yzx1tOhIRquuyN5nd8BfVtoX5jQaJAK2vWFAHzyDsTZiaX0ZX06m0AmbnwRtrIy5yQtjKL7vwxsi4bbmrkjGJ1tGf/rB+z3Pm0HGi3zOeMjIfws6CQeXtYRPecsw7YovvRCgbJvIHXp0FIvUiM/BNsvftfh4V+fb/tycuLNMHi7S899QY6U3zN1Bitiu5xj+LwUcFEJDSCatSYUEgz3VuuLI2xDcOdNETDuvEH7QV5IpRBz98GZm8yvnoU97ZIQ6B/626hWCQLgjiiDuYQyv99WVtFgfMmVkIY92QiskoqtaSLsGtwo92RzmJIvtIBZPcR9zeA7k9iwXre4qX/0WNc6+Z5/aiulO/s999LJ4R7D4aKrQS4d3FVJ6tv0Z85Bau6yAN6eB9bo2+dA62YfePfX6PeUW+Eqp6k2ckGF4GvkH8k039keKSo4RGRkL01ymu+89PPF+yI1mIFzEHNLkUdaQ=
12+
on_success: never
13+
on_failure: always

‎license.md ‎LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) 2017 Sourceboat
3+
Copyright (c) Sourceboat GmbH & Co. KG <info@sourceboat.com>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎readme.md ‎README.md

File renamed without changes.

‎lib/linter.js

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const walk = require('walk')
22
const fs = require('fs')
3+
const os = require('os')
34
const path = require('path')
45
const htmlparser = require('htmlparser2')
56
const cheerio = require('cheerio')
@@ -43,7 +44,11 @@ class Linter {
4344
const fileTemplates = this.extractFileTemplates(fileData)
4445

4546
fileTemplates.forEach((template) => {
46-
const fileErrors = this.pugLinter.checkString(template, filename)
47+
// Remove first and last line-break, as these contain the opening /
48+
// closing <template> tag expressions and should not count as empty
49+
// lines.
50+
const text = template.match(/^[\r\n|\n|\r]?([\s\S]*?)[\r\n|\n|\r]?$/)[1]
51+
const fileErrors = this.pugLinter.checkString(text, filename)
4752
this.lintErrors = this.lintErrors.concat(fileErrors)
4853
})
4954

@@ -57,19 +62,26 @@ class Linter {
5762
}
5863

5964
extractFileTemplates (fileData) {
60-
let templates = []
65+
const content = fileData.toString()
66+
const templates = []
6167

6268
const handler = new htmlparser.DefaultHandler((error, dom) => {
6369
if (error) {
6470
return console.log(error)
6571
}
6672

6773
const $ = cheerio.load(dom)
68-
templates = templates.concat($('template[lang="pug"]').text())
74+
const text = $('template[lang="pug"]').text()
75+
// Determine the amount of lines before the <template> block
76+
const start = content.indexOf(text)
77+
const lines = content.substring(0, start).split(/[\r\n|\n|\r]/g).length
78+
// Insert empty root-level divs on each line, so that code-errors are in
79+
// the right offset, and indentation doesn't trigger errors.
80+
templates.push(`${Array(lines).join(`div${os.EOL}`)}div${text}`)
6981
})
7082

7183
var parser = new htmlparser.Parser(handler)
72-
parser.parseComplete(fileData)
84+
parser.parseComplete(content)
7385
return templates
7486
}
7587
}

‎lib/reporter.js

+6-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
1-
const table = require('text-table')
1+
const os = require('os')
22
const chalk = require('chalk')
33

44
class Reporter {
55
report (messages) {
66
const resultsPerFile = this.getResultsPerFile(messages)
77

8-
let output = '\n'
9-
let total = 0
10-
8+
const output = []
119
for (const filename in resultsPerFile) {
1210
const messages = resultsPerFile[filename].messages
13-
total += messages.length
14-
15-
output += chalk.underline(filename) + '\n'
16-
output += table(messages.map((msg) => [
17-
'',
18-
`${msg.line}${msg.column != null ? `:${msg.column}` : ''}`,
19-
msg.msg
20-
]))
21-
22-
output += '\n\n'
11+
output.push(...messages.map((msg) => msg.message))
2312
}
2413

25-
if (total > 0) {
26-
output += chalk.red.bold(`\u2716 problems: ${total}`)
27-
console.log(output)
14+
if (output.length > 0) {
15+
output.push(chalk.red.bold(`\u2716 Errors: ${output.length}`))
16+
console.log(`${os.EOL}${output.join(`${os.EOL}${os.EOL}`)}${os.EOL}`)
2817
process.exit(1)
2918
}
3019
}

‎package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pug-lint-vue",
3-
"version": "0.3.0",
3+
"version": "0.4.0",
44
"description": "Command line tool to lint Pug templates in Vue single file components.",
55
"keywords": [
66
"lint",
@@ -30,21 +30,21 @@
3030
"precommit": "npm run lint"
3131
},
3232
"dependencies": {
33-
"chalk": "^2.4.2",
33+
"chalk": "^4.0.0",
3434
"cheerio": "^1.0.0-rc.3",
35-
"commander": "^2.20.0",
36-
"htmlparser2": "^3.9.2",
35+
"commander": "^5.0.0",
36+
"htmlparser2": "^4.0.0",
3737
"pug-lint": "^2.6.0",
3838
"text-table": "^0.2.0",
3939
"walk": "^2.3.14"
4040
},
4141
"devDependencies": {
4242
"eslint": "^6.0.1",
43-
"eslint-config-standard": "^12.0.0",
43+
"eslint-config-standard": "^14.0.1",
4444
"eslint-plugin-import": "^2.18.0",
45-
"eslint-plugin-node": "^9.1.0",
45+
"eslint-plugin-node": "^11.0.0",
4646
"eslint-plugin-promise": "^4.2.1",
4747
"eslint-plugin-standard": "^4.0.0",
48-
"husky": "^2.5.0"
48+
"husky": "^4.0.0"
4949
}
5050
}

‎yarn.lock

+495-378
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
This repository has been archived.