Skip to content

Commit

Permalink
fix: windows path separator (#443)
Browse files Browse the repository at this point in the history
* fix: fix windows path separator

* test: remove TODOs
  • Loading branch information
Shinigami committed Jun 25, 2020
1 parent a410107 commit 8048600
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 22 deletions.
8 changes: 8 additions & 0 deletions src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as program from 'commander'
import { existsSync, readFileSync, statSync } from 'fs'
import * as glob from 'glob'
import { IGlob } from 'glob'
import { type as osType } from 'os'
import * as parseGlob from 'parse-glob'
import { dirname, resolve, sep } from 'path'
import * as request from 'request'
Expand All @@ -19,6 +20,8 @@ const formatter: Formatter = require('./formatter')

const pkg = require('../../package.json')

const OS_TYPE = osType()

function map(val: string) {
const objMap: { [name: string]: string | true } = {}
val.split(',').forEach((item) => {
Expand Down Expand Up @@ -446,6 +449,11 @@ function walkPath(

walk.on('match', (file: string) => {
base = base.replace(/^.\//, '')

if (OS_TYPE === 'Windows_NT') {
base = base.replace(/\//g, '\\')
}

callback(base + file)
})
}
Expand Down
8 changes: 1 addition & 7 deletions test/cli/formatters/checkstyle.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ describe('CLI', () => {
it('should have stdout output with formatter checkstyle', (done) => {
const expected = fs
.readFileSync(path.resolve(__dirname, 'checkstyle.xml'), 'utf8')
.replace(
'{{path}}',
path
.resolve(__dirname, 'example.html')
// TODO: we need to fix windows backslash
.replace('\\example', '/example')
)
.replace('{{path}}', path.resolve(__dirname, 'example.html'))

const expectedParts = expected.split('\n')

Expand Down
5 changes: 1 addition & 4 deletions test/cli/formatters/compact.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ describe('CLI', () => {
.readFileSync(path.resolve(__dirname, 'compact.txt'), 'utf8')
.replace(
/\{\{path\}\}/g,
path
.resolve(__dirname, '../../html/executable.html')
// TODO: we need to fix windows backslash
.replace('html\\executable.html', 'html/executable.html')
path.resolve(__dirname, '../../html/executable.html')
)
.replace(/\\u001b/g, '\u001b')

Expand Down
8 changes: 1 addition & 7 deletions test/cli/formatters/html.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ describe('CLI', () => {
it('should have stdout output with formatter html', (done) => {
const expected = fs
.readFileSync(path.resolve(__dirname, 'html.html'), 'utf8')
.replace(
/\{\{path\}\}/g,
path
.resolve(__dirname, 'example.html')
// TODO: we need to fix windows backslash
.replace('\\example', '/example')
)
.replace(/\{\{path\}\}/g, path.resolve(__dirname, 'example.html'))

const expectedParts = expected.split('\n')

Expand Down
5 changes: 1 addition & 4 deletions test/cli/formatters/unix.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ describe('CLI', () => {
.readFileSync(path.resolve(__dirname, 'unix.txt'), 'utf8')
.replace(
/\{\{path\}\}/g,
path
.resolve(__dirname, '../../html/executable.html')
// TODO: we need to fix windows backslash
.replace('html\\executable.html', 'html/executable.html')
path.resolve(__dirname, '../../html/executable.html')
)
.replace(/\\u001b/g, '\u001b')

Expand Down

0 comments on commit 8048600

Please sign in to comment.