Skip to content

Commit 8048600

Browse files
author
Shinigami
authoredJun 25, 2020
fix: windows path separator (#443)
* fix: fix windows path separator * test: remove TODOs
1 parent a410107 commit 8048600

File tree

5 files changed

+12
-22
lines changed

5 files changed

+12
-22
lines changed
 

‎src/cli/htmlhint.ts

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as program from 'commander'
66
import { existsSync, readFileSync, statSync } from 'fs'
77
import * as glob from 'glob'
88
import { IGlob } from 'glob'
9+
import { type as osType } from 'os'
910
import * as parseGlob from 'parse-glob'
1011
import { dirname, resolve, sep } from 'path'
1112
import * as request from 'request'
@@ -19,6 +20,8 @@ const formatter: Formatter = require('./formatter')
1920

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

23+
const OS_TYPE = osType()
24+
2225
function map(val: string) {
2326
const objMap: { [name: string]: string | true } = {}
2427
val.split(',').forEach((item) => {
@@ -446,6 +449,11 @@ function walkPath(
446449

447450
walk.on('match', (file: string) => {
448451
base = base.replace(/^.\//, '')
452+
453+
if (OS_TYPE === 'Windows_NT') {
454+
base = base.replace(/\//g, '\\')
455+
}
456+
449457
callback(base + file)
450458
})
451459
}

‎test/cli/formatters/checkstyle.spec.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ describe('CLI', () => {
99
it('should have stdout output with formatter checkstyle', (done) => {
1010
const expected = fs
1111
.readFileSync(path.resolve(__dirname, 'checkstyle.xml'), 'utf8')
12-
.replace(
13-
'{{path}}',
14-
path
15-
.resolve(__dirname, 'example.html')
16-
// TODO: we need to fix windows backslash
17-
.replace('\\example', '/example')
18-
)
12+
.replace('{{path}}', path.resolve(__dirname, 'example.html'))
1913

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

‎test/cli/formatters/compact.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ describe('CLI', () => {
1111
.readFileSync(path.resolve(__dirname, 'compact.txt'), 'utf8')
1212
.replace(
1313
/\{\{path\}\}/g,
14-
path
15-
.resolve(__dirname, '../../html/executable.html')
16-
// TODO: we need to fix windows backslash
17-
.replace('html\\executable.html', 'html/executable.html')
14+
path.resolve(__dirname, '../../html/executable.html')
1815
)
1916
.replace(/\\u001b/g, '\u001b')
2017

‎test/cli/formatters/html.spec.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@ describe('CLI', () => {
99
it('should have stdout output with formatter html', (done) => {
1010
const expected = fs
1111
.readFileSync(path.resolve(__dirname, 'html.html'), 'utf8')
12-
.replace(
13-
/\{\{path\}\}/g,
14-
path
15-
.resolve(__dirname, 'example.html')
16-
// TODO: we need to fix windows backslash
17-
.replace('\\example', '/example')
18-
)
12+
.replace(/\{\{path\}\}/g, path.resolve(__dirname, 'example.html'))
1913

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

‎test/cli/formatters/unix.spec.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ describe('CLI', () => {
1111
.readFileSync(path.resolve(__dirname, 'unix.txt'), 'utf8')
1212
.replace(
1313
/\{\{path\}\}/g,
14-
path
15-
.resolve(__dirname, '../../html/executable.html')
16-
// TODO: we need to fix windows backslash
17-
.replace('html\\executable.html', 'html/executable.html')
14+
path.resolve(__dirname, '../../html/executable.html')
1815
)
1916
.replace(/\\u001b/g, '\u001b')
2017

0 commit comments

Comments
 (0)
Please sign in to comment.