Skip to content
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

Fix code scanning issues #978

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 @@
});

it('Insert required attributes at correct level', (done) => {
const schema = require(path.join(__dirname, './fixtures/testRequiredProperties.json'));
const schema = require('./fixtures/testRequiredProperties.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '- ';
const completion = parseSetup(content, content.length);
Expand All @@ -822,7 +822,7 @@
});

it('Provide the 3 types when none provided', (done) => {
const schema = require(path.join(__dirname, './fixtures/testArrayMaxProperties.json'));
const schema = require('./fixtures/testArrayMaxProperties.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '- ';
const completion = parseSetup(content, content.length);
Expand Down Expand Up @@ -852,7 +852,7 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '- prop1:\n ';
const completion = parseSetup(content, content.length);
Expand All @@ -876,7 +876,7 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '- prop1:\n p';
const completion = parseSetup(content, content.length);
Expand All @@ -900,7 +900,7 @@
});

it('Provide no completion when maxProperties reached', (done) => {
const schema = require(path.join(__dirname, './fixtures/testArrayMaxProperties.json'));
const schema = require('./fixtures/testArrayMaxProperties.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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('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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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('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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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('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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'test_simpleArrayObject:\n -';
const completion = parseSetup(content, content.length);
Expand All @@ -2615,7 +2615,7 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'test_array_anyOf_2objects:\n - ';
const completion = parseSetup(content, content.length);
Expand All @@ -2658,7 +2658,7 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'test_array_anyOf_2objects:\n -';
const completion = parseSetup(content, content.length);
Expand All @@ -2672,7 +2672,7 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});

it('Array anyOf two objects completion indentation', async () => {
const schema = require(path.join(__dirname, './fixtures/testArrayCompletionSchema.json'));
const schema = require('./fixtures/testArrayCompletionSchema.json');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
} 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 @@

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = `objA:
- name: nameA1
Expand All @@ -215,7 +214,7 @@

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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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('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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
// 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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
// 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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
// 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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
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 @@
});
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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.
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 @@
});
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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.

schemaProvider.addSchemaWithUri(SCHEMA_ID, 'file:///sharedSchema.json', schema.sharedSchema);
schemaProvider.addSchema(SCHEMA_ID, schema.schema);
Expand All @@ -1515,7 +1514,7 @@
});
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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.

schemaProvider.addSchemaWithUri(SCHEMA_ID, 'file:///sharedSchema.json', schema.sharedSchema);
schemaProvider.addSchema(SCHEMA_ID, schema.schema);
Expand All @@ -1528,7 +1527,7 @@
});
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');

Check failure

Code scanning / ESLint

Disallow `require` statements except in import statements Error test

Require statement not part of import statement.

schemaProvider.addSchemaWithUri(sharedSchemaId, 'file:///sharedSchema.json', schema.sharedSchema);
schemaProvider.addSchema(SCHEMA_ID, schema.schema);
Expand Down
Loading