Skip to content

Fix code scanning issues #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions test/autoCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this trades one code scanning alert for another, though the new one is not as bad as the old one.

I do agree with the new failed checks. The proper solution would be to write this at the top of the file:

import schema = require('./fixtures/testRequiredProperties.json');

schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '- top:\n prop1: demo\n- ';
const completion = parseSetup(content, content.length);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions test/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
9 changes: 4 additions & 5 deletions test/schemaValidation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 ';
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down