Skip to content

Conversation

@aviadr1
Copy link

@aviadr1 aviadr1 commented Nov 11, 2025

Summary

This PR adds support for specifying typeCheckingMode within individual executionEnvironments entries in the configuration file. This allows different folders in a project to use different type checking strictness levels.

Motivation

Previously, to apply different type checking strictness to different folders, users had to:

  1. Manually specify dozens of individual diagnostic rules for each execution environment, or
  2. Use the strict array (which only supports upgrading to strict mode, not other modes like "recommended")

This made it difficult to:

  • Apply stricter checking to new code while keeping legacy code at a lower level
  • Gradually migrate a codebase to stricter checking folder-by-folder
  • Use "recommended" mode (basedpyright's default) only in specific parts of a project

Changes

Implementation

  • Modified _initExecutionEnvironmentFromJson in configOptions.ts to check for typeCheckingMode and use it to generate the base diagnostic rule set
  • The implementation follows the same pattern as other per-environment settings like pythonVersion and pythonPlatform
  • Individual diagnostic rule overrides still take precedence over the typeCheckingMode setting

Tests

Added comprehensive test coverage in config.test.ts:

  • ✅ typeCheckingMode sets diagnostic rules correctly for different modes
  • ✅ Individual rule overrides take precedence over typeCheckingMode
  • ✅ Invalid typeCheckingMode values are validated and logged as errors
  • ✅ Type validation (must be a string)
  • ✅ Inheritance from global setting when not specified
  • ✅ All modes (off, basic, standard, strict, recommended, all) work correctly

All existing tests pass.

Documentation

Updated docs/configuration/config-files.md:

  • Added typeCheckingMode to the Execution Environment Options section
  • Updated sample config files to demonstrate the feature
  • Clarified precedence rules

Example Usage

{
  "typeCheckingMode": "standard",
  "executionEnvironments": [
    {
      "root": "src/legacy",
      "typeCheckingMode": "basic"
    },
    {
      "root": "src/new_code",
      "typeCheckingMode": "recommended"
    }
  ]
}

Related

Fixes #1638

Checklist

  • Implementation complete
  • Tests added and passing
  • Documentation updated
  • All existing tests pass

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

aviadr1 and others added 3 commits November 11, 2025 23:20
Add support for specifying typeCheckingMode within individual
executionEnvironments entries in the configuration file. This allows
different folders in a project to use different type checking strictness
levels (off, basic, standard, strict, recommended, all).

Previously, users had to manually specify dozens of individual diagnostic
rules to achieve different strictness levels per folder. This change makes
it much cleaner and more maintainable.

Features:
- typeCheckingMode can be specified in any executionEnvironment
- If specified, it overrides the global typeCheckingMode for that folder
- Individual diagnostic rule overrides still take precedence
- All modes (off, basic, standard, strict, recommended, all) are supported
- Invalid modes are validated and logged as errors

Changes:
- Modified _initExecutionEnvironmentFromJson to check for typeCheckingMode
- Added comprehensive test coverage for all scenarios
- Updated documentation with examples

Fixes: DetachHead#1638

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add a test that specifically verifies basedpyright's 'recommended' mode
applies the correct diagnostic rules when used in executionEnvironments,
including basedpyright-specific rules like reportAny and reportExplicitAny.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
… different modes

This test verifies that:
- Multiple execution environments can have different typeCheckingModes
- Each environment's settings are independent and don't interfere
- Environments with 'basic', 'recommended', 'strict', and inherited 'standard' modes
  all have the correct diagnostic rules simultaneously
- Specifically verifies that 'recommended' mode's basedpyright-specific rules
  (reportAny, reportExplicitAny, failOnWarnings) are ONLY enabled in the
  'recommended' environment and NOT in the others

This addresses the concern that the previous tests only verified one
execution environment at a time and didn't prove isolation between environments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copy link
Owner

@DetachHead DetachHead left a comment

Choose a reason for hiding this comment

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

thanks for the contribution!

for future reference, while i don't mind contributors using ai as long as the code is good (this change looks good, just a few minor suggestions), i'd prefer if it's not used for issue and PR descriptions as LLMs typically too wordy without really saying much. a brief description or just an issue link is fine with me most of the time

aviadr1 and others added 9 commits November 18, 2025 10:06
- Link to valid values in docs instead of duplicating
- Remove subjective language from typeCheckingMode description
- Add reportMissingImports to examples to show diagnostic overrides work with typeCheckingMode
- Extract getDiagnosticRuleSetFromString helper function to eliminate code duplication
- Add typeCheckingMode property to ExecutionEnvironment class
- Fix destructuring typo in test (strictEnv, strictEnv -> strictEnv, basicEnv)
- Fix error count assertion formatting
- Import allTypeCheckingModes from configOptions.ts instead of hardcoding

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Reverted unintentional quote character change on line 317 that was
introduced during merge conflict resolution.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The previous commit incorrectly changed curly quotes to straight quotes.
The main branch uses curly quotes, so reverting to match.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Changed straight apostrophe (') to curly apostrophe (') in 'file's'
on line 325 to match the formatting style used in main branch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@aviadr1 aviadr1 requested a review from DetachHead November 18, 2025 09:16
@aviadr1
Copy link
Author

aviadr1 commented Nov 18, 2025

@DetachHead thanks for the review! I addressed all comments. please re-review

let baseDiagnosticRuleSet = configDiagnosticRuleSet;
if (envObj.typeCheckingMode !== undefined) {
if (typeof envObj.typeCheckingMode === 'string') {
if ((allTypeCheckingModes as readonly string[]).includes(envObj.typeCheckingMode)) {
Copy link
Owner

@DetachHead DetachHead Nov 19, 2025

Choose a reason for hiding this comment

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

did the ai write this? it looks like it's duplicated even more now. is it trying to replace the initializeTypeCheckingModeFromString and initializeTypeCheckingMode functions with this new getDiagnosticRuleSetFromString function? if so, how come it's only called in one spot but the existing usages of those functions are still there?

@github-actions

This comment has been minimized.

@aviadr1
Copy link
Author

aviadr1 commented Nov 21, 2025

did the ai write this? it looks like it's duplicated even more now. is it trying to replace the initializeTypeCheckingModeFromString and initializeTypeCheckingMode functions with this new getDiagnosticRuleSetFromString function? if so, how come it's only called in one spot but the existing usages of those functions are still there?

thanks for the review! yes @DetachHead I am using AI for this entire PR because I dont have familiarity with typescript or the repo and I wouldnt be able to add this feature otherwise. thanks for the patience.

aviadr1 and others added 2 commits November 21, 2025 20:31
…edback

- Extract validation logic into reusable validateTypeCheckingMode helper
- Change parameter type from 'any' to 'unknown' for better type safety
- Remove redundant tests (type validation and inheritance tests)
- Fix error assertion to use strictEqual
- Maintain original error message format for backward compatibility

This addresses PR review feedback from DetachHead.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Rename validateTypeCheckingMode to _validateTypeCheckingMode (private static method naming)
- Rename getDiagnosticRuleSetFromString to _getDiagnosticRuleSetFromString
- Move private static methods after public methods to fix member ordering

This fixes ESLint errors:
- @typescript-eslint/naming-convention
- @typescript-eslint/member-ordering

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@aviadr1 aviadr1 requested a review from DetachHead November 21, 2025 21:13
@aviadr1
Copy link
Author

aviadr1 commented Nov 21, 2025

did the ai write this? it looks like it's duplicated even more now. is it trying to replace the initializeTypeCheckingModeFromString and initializeTypeCheckingMode functions with this new getDiagnosticRuleSetFromString function? if so, how come it's only called in one spot but the existing usages of those functions are still there?

thanks for the review! yes @DetachHead I am using AI for this entire PR because I dont have familiarity with typescript or the repo and I wouldnt be able to add this feature otherwise. thanks for the patience.

@DetachHead please re-review I took extra care to get claude to remove any duplications, and also to lint the content.

@github-actions

This comment has been minimized.

Comment on lines 812 to 833
test('typeCheckingMode must be a string in executionEnvironment', () => {
const cwd = UriEx.file(normalizePath(process.cwd()));
const configOptions = new ConfigOptions(cwd);

const json = {
executionEnvironments: [
{
root: 'src/invalid',
typeCheckingMode: 123,
},
],
};

const fs = new TestFileSystem(/* ignoreCase */ false);
const console = new ErrorTrackingNullConsole();
const sp = createServiceProvider(fs, console);
configOptions.initializeFromJson(json, cwd, sp, new NoAccessHost());
configOptions.setupExecutionEnvironments(json, cwd, console);

assert(console.errors.length === 1);
assert(console.errors[0].includes('typeCheckingMode must be a string'));
});
Copy link
Owner

Choose a reason for hiding this comment

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

why remove this test? i don't think there's another test for it

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Support typeCheckingMode in executionEnvironments

2 participants