allegro / typescript-strict-plugin

Typescript plugin that allows turning on strict mode in specific files or directories.
MIT License
332 stars 29 forks source link

Don't match path on prefix alone #68

Closed heyimalex closed 6 months ago

heyimalex commented 7 months ago

Noticed that path/to/good was matching path/to/goodness-no/file.ts, so just the prefix and not the exact directory. I will maybe add tests this weekend.

kellyrmilligan commented 6 months ago

would love to see this merged if it passes tests. I have the same issue.

kellyrmilligan commented 6 months ago

if anyone else ends up here, I ended up for now just using pnpm's built in patch feature. another option if not using pnpm would be:

https://www.npmjs.com/package/patch-package

KostkaBrukowa commented 6 months ago

Thanks for contribution! Published with 2.3.2

solomkinmv commented 5 months ago

Hey. My use case was to use exact file path like path/to/goodness-no/file.ts, but looks like this change breaks it. Now exact matches doesn't work any more

heyimalex commented 4 months ago

@solomkinmv If you want to contribute, I think a fix would be:

const posixFilePath = getPosixFilePath(filePath);
const posixStrictPath = getPosixFilePath(absolutePathToStrictFiles);
return posixFilePath === posixStrictPath || posixFilePath.startsWith(posixStrictPath + path.posix.sep);
floklein commented 3 weeks ago

This breaks every file paths. So the README.md is not accurate anymore:

{
  "compilerOptions": {
    ...
    "strict": false,
    "plugins": [
      {
        "name": "typescript-strict-plugin",
        "paths": [
          "./src",
          "/absolute/path/to/source/"
        ],
        "exclude": [
          "./src/tests",
          "./src/fileToExclude.ts"
        ],
        "excludePattern": [
          "**/*.spec.ts"
        ]
      }
    ]
  }
}
floklein commented 3 weeks ago

Submitted a PR (https://github.com/allegro/typescript-strict-plugin/pull/86) to fix this. Thanks @heyimalex!