From 6800df8dd2df17edb215941b26efcbe54cd90279 Mon Sep 17 00:00:00 2001 From: Remco Haszing Date: Fri, 7 Jun 2024 11:52:22 +0200 Subject: [PATCH] Fix code scanning issues This resolves 30 occurrences of: ```ts require(path.join(__dirname), './relative-path')) ``` By replacing them with the equivalent: ``` require('./relative-path') ``` --- test/autoCompletion.test.ts | 40 +++++++++++++++++----------------- test/autoCompletionFix.test.ts | 5 ++--- test/schema.test.ts | 8 +++---- test/schemaValidation.test.ts | 9 ++++---- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/test/autoCompletion.test.ts b/test/autoCompletion.test.ts index eba8fa6d..b1013eec 100644 --- a/test/autoCompletion.test.ts +++ b/test/autoCompletion.test.ts @@ -786,7 +786,7 @@ describe('Auto Completion Tests', () => { }); it('Insert required attributes at correct level', (done) => { - const schema = require(path.join(__dirname, './fixtures/testRequiredProperties.json')); + const schema = require('./fixtures/testRequiredProperties.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = '- top:\n prop1: demo\n- '; const completion = parseSetup(content, content.length); @@ -804,7 +804,7 @@ describe('Auto Completion Tests', () => { }); it('Insert required attributes at correct level even on first element', (done) => { - const schema = require(path.join(__dirname, './fixtures/testRequiredProperties.json')); + const schema = require('./fixtures/testRequiredProperties.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = '- '; const completion = parseSetup(content, content.length); @@ -822,7 +822,7 @@ describe('Auto Completion Tests', () => { }); it('Provide the 3 types when none provided', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayMaxProperties.json')); + const schema = require('./fixtures/testArrayMaxProperties.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = '- '; const completion = parseSetup(content, content.length); @@ -852,7 +852,7 @@ describe('Auto Completion Tests', () => { }); it('Provide the 2 types when one is provided', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayMaxProperties.json')); + const schema = require('./fixtures/testArrayMaxProperties.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = '- prop1:\n '; const completion = parseSetup(content, content.length); @@ -876,7 +876,7 @@ describe('Auto Completion Tests', () => { }); it('Provide the 2 types when one is provided and the second is typed', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayMaxProperties.json')); + const schema = require('./fixtures/testArrayMaxProperties.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = '- prop1:\n p'; const completion = parseSetup(content, content.length); @@ -900,7 +900,7 @@ describe('Auto Completion Tests', () => { }); it('Provide no completion when maxProperties reached', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayMaxProperties.json')); + const schema = require('./fixtures/testArrayMaxProperties.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = '- prop1:\n prop2:\n '; const completion = parseSetup(content, content.length); @@ -1041,7 +1041,7 @@ describe('Auto Completion Tests', () => { describe('Array Specific Tests', function () { it('Should insert empty array item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testStringArray.json')); + const schema = require('./fixtures/testStringArray.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'fooBa'; // len: 5 const completion = parseSetup(content, content.lastIndexOf('Ba') + 2); // pos: 3+2 @@ -1842,7 +1842,7 @@ describe('Auto Completion Tests', () => { describe('Indentation Specific Tests', function () { it('Indent should be considered with position relative to slash', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayIndent.json')); + const schema = require('./fixtures/testArrayIndent.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'install:\n - he'; // len: 15 const completion = parseSetup(content, content.lastIndexOf('he') + 2); // pos: 13+2 @@ -1860,7 +1860,7 @@ describe('Auto Completion Tests', () => { }); it('Large indent should be considered with position relative to slash', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayIndent.json')); + const schema = require('./fixtures/testArrayIndent.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'install:\n - he'; // len: 25 const completion = parseSetup(content, content.lastIndexOf('he') + 2); // pos: 23+2 @@ -1878,7 +1878,7 @@ describe('Auto Completion Tests', () => { }); it('Tab indent should be considered with position relative to slash', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayIndent.json')); + const schema = require('./fixtures/testArrayIndent.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'install:\n -\t he'; // len: 27 const completion = parseSetup(content, content.lastIndexOf('he') + 2); // pos: 25+2 @@ -2601,7 +2601,7 @@ describe('Auto Completion Tests', () => { describe('Array completion', () => { it('Simple array object completion with "-" without any item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_simpleArrayObject:\n -'; const completion = parseSetup(content, content.length); @@ -2615,7 +2615,7 @@ describe('Auto Completion Tests', () => { }); it('Simple array object completion without "-" after array item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_simpleArrayObject:\n - obj1:\n name: 1\n '; const completion = parseSetup(content, content.length); @@ -2628,7 +2628,7 @@ describe('Auto Completion Tests', () => { }); it('Simple array object completion with "-" after array item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_simpleArrayObject:\n - obj1:\n name: 1\n -'; const completion = parseSetup(content, content.length); @@ -2642,7 +2642,7 @@ describe('Auto Completion Tests', () => { }); it('Array anyOf two objects completion with "- " without any item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_array_anyOf_2objects:\n - '; const completion = parseSetup(content, content.length); @@ -2658,7 +2658,7 @@ describe('Auto Completion Tests', () => { }); it('Array anyOf two objects completion with "-" without any item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_array_anyOf_2objects:\n -'; const completion = parseSetup(content, content.length); @@ -2672,7 +2672,7 @@ describe('Auto Completion Tests', () => { }); it('Simple array object completion without "-" befor array empty item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_simpleArrayObject:\n |\n| -'; // len: 30, pos: 26 const completion = parseSetup(content); @@ -2685,7 +2685,7 @@ describe('Auto Completion Tests', () => { }); it('Array anyOf two objects completion without "-" after array item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_array_anyOf_2objects:\n - obj1:\n name: 1\n '; const completion = parseSetup(content, content.length); @@ -2697,7 +2697,7 @@ describe('Auto Completion Tests', () => { }); it('Array nested anyOf without "-" should return all array items', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_array_nested_anyOf:\n - obj1:\n name:1\n '; const completion = parseSetup(content, content.length); @@ -2709,7 +2709,7 @@ describe('Auto Completion Tests', () => { }); it('Array anyOf two objects completion with "-" after array item', (done) => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_array_anyOf_2objects:\n - obj1:\n name: 1\n -'; const completion = parseSetup(content, content.length); @@ -2723,7 +2723,7 @@ describe('Auto Completion Tests', () => { }); it('Array anyOf two objects completion indentation', async () => { - const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json')); + const schema = require('./fixtures/testArrayCompletionSchema.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'test_array_anyOf_2objects:\n - obj'; const completion = await parseSetup(content, content.length); diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts index c720ce76..492b8883 100644 --- a/test/autoCompletionFix.test.ts +++ b/test/autoCompletionFix.test.ts @@ -17,7 +17,6 @@ import { } from './utils/testHelper'; import { expect } from 'chai'; import { createExpectedCompletion } from './utils/verifyError'; -import * as path from 'path'; import { JSONSchema } from './../src/languageservice/jsonSchema'; describe('Auto Completion Fix Tests', () => { @@ -200,7 +199,7 @@ spec: it('should complete array', async () => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schema = require(path.join(__dirname, './fixtures/test-nested-object-array.json')); + const schema = require('./fixtures/test-nested-object-array.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = `objA: - name: nameA1 @@ -215,7 +214,7 @@ objB: it('should complete array item for "oneOf" schema', async () => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schema = require(path.join(__dirname, './fixtures/test-completion-oneOf.json')); + const schema = require('./fixtures/test-completion-oneOf.json'); schemaProvider.addSchema(SCHEMA_ID, schema); const content = `metadata: Selector: diff --git a/test/schema.test.ts b/test/schema.test.ts index 1747b1c4..ee32f0c5 100644 --- a/test/schema.test.ts +++ b/test/schema.test.ts @@ -582,15 +582,15 @@ describe('JSON Schema', () => { describe('Test schema priority', function () { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schemaAssociationSample = require(path.join(__dirname, './fixtures/sample-association.json')); + const schemaAssociationSample = require('./fixtures/sample-association.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires - const schemaStoreSample = require(path.join(__dirname, './fixtures/sample-schemastore.json')); + const schemaStoreSample = require('./fixtures/sample-schemastore.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires - const schemaSettingsSample = require(path.join(__dirname, './fixtures/sample-settings.json')); + const schemaSettingsSample = require('./fixtures/sample-settings.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires const schemaModelineSample = path.join(__dirname, './fixtures/sample-modeline.json'); // eslint-disable-next-line @typescript-eslint/no-var-requires - const schemaDefaultSnippetSample = require(path.join(__dirname, './fixtures/defaultSnippets-const-if-else.json')); + const schemaDefaultSnippetSample = require('./fixtures/defaultSnippets-const-if-else.json'); const languageSettingsSetup = new ServiceSetup().withCompletion(); it('Modeline Schema takes precendence over all other schema APIs', async () => { diff --git a/test/schemaValidation.test.ts b/test/schemaValidation.test.ts index 71268db7..5d3ce675 100644 --- a/test/schemaValidation.test.ts +++ b/test/schemaValidation.test.ts @@ -16,7 +16,6 @@ import { MissingRequiredPropWarning, } from './utils/errorMessages'; import * as assert from 'assert'; -import * as path from 'path'; import { Diagnostic, DiagnosticSeverity, Position } from 'vscode-languageserver-types'; import { expect } from 'chai'; import { SettingsState, TextDocumentTestManager } from '../src/yamlSettings'; @@ -1486,7 +1485,7 @@ obj: }); it('should distinguish types in error "Incorrect type (Expected "type1 | type2 | type3")"', async () => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schema = require(path.join(__dirname, './fixtures/testMultipleSimilarSchema.json')); + const schema = require('./fixtures/testMultipleSimilarSchema.json'); schemaProvider.addSchemaWithUri(SCHEMA_ID, 'file:///sharedSchema.json', schema.sharedSchema); schemaProvider.addSchema(SCHEMA_ID, schema.schema); const content = 'test_anyOf_objects:\n '; @@ -1502,7 +1501,7 @@ obj: }); it('should combine types in "Incorrect type error"', async () => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schema = require(path.join(__dirname, './fixtures/testMultipleSimilarSchema.json')); + const schema = require('./fixtures/testMultipleSimilarSchema.json'); schemaProvider.addSchemaWithUri(SCHEMA_ID, 'file:///sharedSchema.json', schema.sharedSchema); schemaProvider.addSchema(SCHEMA_ID, schema.schema); @@ -1515,7 +1514,7 @@ obj: }); it('should combine const value', async () => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schema = require(path.join(__dirname, './fixtures/testMultipleSimilarSchema.json')); + const schema = require('./fixtures/testMultipleSimilarSchema.json'); schemaProvider.addSchemaWithUri(SCHEMA_ID, 'file:///sharedSchema.json', schema.sharedSchema); schemaProvider.addSchema(SCHEMA_ID, schema.schema); @@ -1528,7 +1527,7 @@ obj: }); it('should distinguish types in error: "Missing property from multiple schemas"', async () => { // eslint-disable-next-line @typescript-eslint/no-var-requires - const schema = require(path.join(__dirname, './fixtures/testMultipleSimilarSchema.json')); + const schema = require('./fixtures/testMultipleSimilarSchema.json'); schemaProvider.addSchemaWithUri(sharedSchemaId, 'file:///sharedSchema.json', schema.sharedSchema); schemaProvider.addSchema(SCHEMA_ID, schema.schema);