Repository: stoplightio/spectral
Pull request #740 (2019-11-06 15:17:53)

fix: unixify glob patterns
Fixes https://github.com/stoplightio/spectral/issues/679

**Checklist**

- [x] Tests added / updated
- [x] Docs added / updated

**Does this PR introduce a breaking change?**

- [ ] Yes
- [x] No

cc @nulltoken, I gave it a try manually under Windows using Powershell and it did the trick, but since I'm certainly more of a Unix guy, so if you'd like to verify it on your own and see if you are issues are gone, you are more than welcome to do so.


nulltoken: @p0lip ![image](https://user-images.githubusercontent.com/92363/68318250-c9571300-00bc-11ea-830b-630cbcf655ad.png)


Patch:
diff --git a/src/cli/services/linter/utils/listFiles.ts b/src/cli/services/linter/utils/listFiles.ts
index 0f57cd7c..a810a3cb 100644
--- a/src/cli/services/linter/utils/listFiles.ts
+++ b/src/cli/services/linter/utils/listFiles.ts
@@ -5,7 +5,7 @@ export async function listFiles(pattens: string[]): Promise<string[]> {
   const { files, urls } = pattens.reduce<{ files: string[]; urls: string[] }>(
     (group, pattern) => {
       if (!/^https?:\/\//.test(pattern)) {
-        group.files.push(pattern);
+        group.files.push(pattern.replace(/\\/g, '/'));
       } else {
         group.urls.push(pattern);
       }


Test patch:
diff --git a/src/cli/services/__tests__/linter.test.ts b/src/cli/services/__tests__/linter.test.ts
index c9ed89c9..34309bc7 100644
--- a/src/cli/services/__tests__/linter.test.ts
+++ b/src/cli/services/__tests__/linter.test.ts
@@ -364,6 +364,43 @@ describe('Linter service', () => {
         ]),
       );
     });
+
+    it('unixifies patterns', () => {
+      return expect(run(`lint src\\__tests__\\__fixtures__\\petstore.invalid-schema.*.json`)).resolves.toEqual(
+        expect.arrayContaining([
+          expect.objectContaining({
+            code: 'invalid-ref',
+            path: ['paths', '/pets', 'get', 'responses', '200', 'content', 'application/json', 'schema', '$ref'],
+            source: join(process.cwd(), 'src/__tests__/__fixtures__/petstore.invalid-schema.oas3.json'),
+          }),
+          expect.objectContaining({
+            code: 'invalid-ref',
+            path: ['paths', '/pets', 'get', 'responses', 'default', 'content', 'application/json', 'schema', '$ref'],
+            source: join(process.cwd(), 'src/__tests__/__fixtures__/petstore.invalid-schema.oas3.json'),
+          }),
+          expect.objectContaining({
+            code: 'invalid-ref',
+            path: ['paths', '/pets', 'get', 'responses', 'default', 'content', 'application/json', 'schema', '$ref'],
+            source: join(process.cwd(), 'src/__tests__/__fixtures__/petstore.invalid-schema.oas3.json'),
+          }),
+          expect.objectContaining({
+            code: 'valid-example-in-schemas',
+            path: ['components', 'schemas', 'foo', 'example'],
+            source: join(process.cwd(), 'src/__tests__/__fixtures__/petstore.invalid-schema.oas3.json'),
+          }),
+          expect.objectContaining({
+            code: 'unused-components-schema',
+            path: ['components', 'schemas', 'Pets'],
+            source: join(process.cwd(), 'src/__tests__/__fixtures__/petstore.invalid-schema.oas3.json'),
+          }),
+          expect.objectContaining({
+            code: 'oas3-schema',
+            path: ['paths', '/pets', 'get', 'responses', '200'],
+            source: join(process.cwd(), 'src/__tests__/__fixtures__/petstore.invalid-schema.oas3.json'),
+          }),
+        ]),
+      );
+    });
   });
 
   describe('--ruleset', () => {
diff --git a/src/cli/services/linter/utils/__tests__/listFiles.spec.ts b/src/cli/services/linter/utils/__tests__/listFiles.spec.ts
new file mode 100644
index 00000000..f3fc328f
--- /dev/null
+++ b/src/cli/services/linter/utils/__tests__/listFiles.spec.ts
@@ -0,0 +1,14 @@
+import * as fg from 'fast-glob';
+import { listFiles } from '../listFiles';
+
+jest.mock('fast-glob');
+
+describe('listFiles CLI util', () => {
+  it('unixify paths', () => {
+    listFiles(['.\\repro\\lib.yaml', './foo/*.json', '.\\src\\__tests__\\__fixtures__\\*.oas.json']);
+    expect(fg).toBeCalledWith(['./repro/lib.yaml', './foo/*.json', './src/__tests__/__fixtures__/*.oas.json'], {
+      dot: true,
+      absolute: true,
+    });
+  });
+});