Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pehbehbeh committed Apr 24, 2020
2 parents 5cdf09e + e66a09e commit 39d9f93
Show file tree
Hide file tree
Showing 7 changed files with 528 additions and 408 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
language: node_js
node_js:
- '8'
- '10'
- '12'
cache:
yarn: true
script:
- yarn run lint
notifications:
slack:
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=
on_success: never
on_failure: always
2 changes: 1 addition & 1 deletion license.md → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

Copyright (c) 2017 Sourceboat
Copyright (c) Sourceboat GmbH & Co. KG <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
File renamed without changes.
20 changes: 16 additions & 4 deletions lib/linter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const walk = require('walk')
const fs = require('fs')
const os = require('os')
const path = require('path')
const htmlparser = require('htmlparser2')
const cheerio = require('cheerio')
Expand Down Expand Up @@ -43,7 +44,11 @@ class Linter {
const fileTemplates = this.extractFileTemplates(fileData)

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

Expand All @@ -57,19 +62,26 @@ class Linter {
}

extractFileTemplates (fileData) {
let templates = []
const content = fileData.toString()
const templates = []

const handler = new htmlparser.DefaultHandler((error, dom) => {
if (error) {
return console.log(error)
}

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

var parser = new htmlparser.Parser(handler)
parser.parseComplete(fileData)
parser.parseComplete(content)
return templates
}
}
Expand Down
23 changes: 6 additions & 17 deletions lib/reporter.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
const table = require('text-table')
const os = require('os')
const chalk = require('chalk')

class Reporter {
report (messages) {
const resultsPerFile = this.getResultsPerFile(messages)

let output = '\n'
let total = 0

const output = []
for (const filename in resultsPerFile) {
const messages = resultsPerFile[filename].messages
total += messages.length

output += chalk.underline(filename) + '\n'
output += table(messages.map((msg) => [
'',
`${msg.line}${msg.column != null ? `:${msg.column}` : ''}`,
msg.msg
]))

output += '\n\n'
output.push(...messages.map((msg) => msg.message))
}

if (total > 0) {
output += chalk.red.bold(`\u2716 problems: ${total}`)
console.log(output)
if (output.length > 0) {
output.push(chalk.red.bold(`\u2716 Errors: ${output.length}`))
console.log(`${os.EOL}${output.join(`${os.EOL}${os.EOL}`)}${os.EOL}`)
process.exit(1)
}
}
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pug-lint-vue",
"version": "0.3.0",
"version": "0.4.0",
"description": "Command line tool to lint Pug templates in Vue single file components.",
"keywords": [
"lint",
Expand Down Expand Up @@ -30,21 +30,21 @@
"precommit": "npm run lint"
},
"dependencies": {
"chalk": "^2.4.2",
"chalk": "^4.0.0",
"cheerio": "^1.0.0-rc.3",
"commander": "^2.20.0",
"htmlparser2": "^3.9.2",
"commander": "^5.0.0",
"htmlparser2": "^4.0.0",
"pug-lint": "^2.6.0",
"text-table": "^0.2.0",
"walk": "^2.3.14"
},
"devDependencies": {
"eslint": "^6.0.1",
"eslint-config-standard": "^12.0.0",
"eslint-config-standard": "^14.0.1",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-node": "^9.1.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.0",
"husky": "^2.5.0"
"husky": "^4.0.0"
}
}
Loading

0 comments on commit 39d9f93

Please sign in to comment.