From 8048600e5b1568d4a4b469e822bd72a94502b242 Mon Sep 17 00:00:00 2001 From: Shinigami Date: Thu, 25 Jun 2020 21:46:31 +0200 Subject: [PATCH] fix: windows path separator (#443) * fix: fix windows path separator * test: remove TODOs --- src/cli/htmlhint.ts | 8 ++++++++ test/cli/formatters/checkstyle.spec.js | 8 +------- test/cli/formatters/compact.spec.js | 5 +---- test/cli/formatters/html.spec.js | 8 +------- test/cli/formatters/unix.spec.js | 5 +---- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/cli/htmlhint.ts b/src/cli/htmlhint.ts index 3a3557982..f7191a24b 100644 --- a/src/cli/htmlhint.ts +++ b/src/cli/htmlhint.ts @@ -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' @@ -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) => { @@ -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) }) } diff --git a/test/cli/formatters/checkstyle.spec.js b/test/cli/formatters/checkstyle.spec.js index 256117bf2..7ab2af9b7 100644 --- a/test/cli/formatters/checkstyle.spec.js +++ b/test/cli/formatters/checkstyle.spec.js @@ -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') diff --git a/test/cli/formatters/compact.spec.js b/test/cli/formatters/compact.spec.js index 636f5cf4d..cd0f8d324 100644 --- a/test/cli/formatters/compact.spec.js +++ b/test/cli/formatters/compact.spec.js @@ -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') diff --git a/test/cli/formatters/html.spec.js b/test/cli/formatters/html.spec.js index 519b77883..67e38d171 100644 --- a/test/cli/formatters/html.spec.js +++ b/test/cli/formatters/html.spec.js @@ -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') diff --git a/test/cli/formatters/unix.spec.js b/test/cli/formatters/unix.spec.js index 10f02e60a..bee9348b6 100644 --- a/test/cli/formatters/unix.spec.js +++ b/test/cli/formatters/unix.spec.js @@ -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')