Skip to content
Merged
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
6 changes: 4 additions & 2 deletions packages/pyright-internal/src/common/configOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1577,11 +1577,13 @@ export class ConfigOptions {
this.initializedFromJson = true;
const console = serviceProvider.tryGet(ServiceKeys.console) ?? new NullConsole();

// we initialize it with `extends` because this option gets read before this function gets called
// 'executionEnvironments' also gets read elsewhere
const unusedConfigDetector = new UnusedConfigDetector<Record<string, object>>(configObj, [
// We ignore these because they get read elsewhere:
'extends',
'executionEnvironments',
// VS Code supports setting "$schema" in a JSON file to pick a validation schema.
// See https://code.visualstudio.com/docs/languages/json#_mapping-in-the-json
'$schema',
]);
configObj = unusedConfigDetector.proxy;

Expand Down
20 changes: 20 additions & 0 deletions packages/pyright-internal/src/tests/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,26 @@ describe(`config test'}`, () => {
assert.equal(configOptions.executionEnvironments[0].pythonPlatform, 'Linux');
});

test('$schema is recognized', () => {
const cwd = UriEx.file(normalizePath(process.cwd()));

const configOptions = new ConfigOptions(cwd);

const json = {
$schema:
'https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json',
typeCheckingMode: 'basic',
};

const fs = new TestFileSystem(/* ignoreCase */ false);
const console = new ErrorTrackingNullConsole();

const sp = createServiceProvider(fs, console);
configOptions.initializeFromJson(json, cwd, sp, new NoAccessHost());

assert.deepStrictEqual(console.errors, []);
});

describe('invalid config', () => {
test('unknown top-level option', () => {
const cwd = UriEx.file(normalizePath(process.cwd()));
Expand Down