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

Glob to exclude __tests__ folder is not working as expected #38

Closed
saulo-okada-zs opened this issue Feb 28, 2024 · 5 comments
Closed

Glob to exclude __tests__ folder is not working as expected #38

saulo-okada-zs opened this issue Feb 28, 2024 · 5 comments

Comments

@saulo-okada-zs
Copy link

Describe the bug
I'm currently working in a monorepo and want to enforce the Kebab Case convention for my domains folder but exclude all the __tests__ folders inside it.
I've tried to use the expression described in the documentation but it does not work as expected on my project.
If I use the full path, it works as expected. But if I change the intermediate folders for /**/, then it doesn't work.

Expected behavior
Files inside the __tests__ should not throw check-file/folder-naming-convention error

Plugin configuration

[.eslintrc.base.json]
...
    "check-file/folder-naming-convention": [
      "error",
      {
        "domains/**/!(__tests__)/**": "KEBAB_CASE", // this doesn't work
        "domains/sub-domain-a/src/!(__tests__)/**": "KEBAB_CASE", // this works
        "domains/**/src/!(__tests__)/**": "KEBAB_CASE", // this works but I want to have a more flexible configuration
      },
    ],

Project structure
If applicable, add a minimal reproducible project structure generated by the tree cmd like the one below.

.
├── domains
│   ├── sub-domain-a
│   │   ├── src
│   │   │   └── __tests__
│   │   │   │   └── test.ts
│   ├── sub-domain-b
│   │   ├── app
│   │   │   └── __tests__
│   │   │   │   └── test.js
│   ├── sub-domain-c
│   │   ├── feature-a
│   │   │   ├── src
│   │   │   │   └── __tests__
│   │   │   │   │   └── test.js
├── libs
├── scripts
├── package-lock.json
├── package.json
└── .eslintrc.base.json

Desktop:

  • OS: macOS Sonoma
@dukeluo
Copy link
Owner

dukeluo commented Feb 29, 2024

@saulo-okada-zs monorepo has more context, could you share a minimal reproducible monorepo project on github so I can work on this?

@saulo-okada-zs
Copy link
Author

saulo-okada-zs commented Feb 29, 2024

Hey @dukeluo!
Thank you for your fast response.
I can try to create something for you.

Meanwhile, here is some info about our monorepo:

  • we are using Lerna
  • we have our .eslintrc.base.json and tsconfig.base.json at the root of the project
  • Inside each of the sub-domains folders, we have a .eslint.json that is extending our base configuration
  • Inside each of the sub-domains folders, we also have a tsconfig.json that is extending our base configuration

I've been doing some tests since yesterday and noticed one interesting behaviour

  • Using the full path in the configuration works properly
    • example: domains/sub-domain-a/app/src/!(__tests__)/**
  • Using partial path it works properly as well
    • example1: domains/sub-domain-a/**/src/!(__tests__)/**
    • example2: domains/**/src/!(__tests__)/**
  • But when I try removing all the intermediate folders, it doesn't work
    • example: domains/**/!(__tests__)/**

@saulo-okada-zs
Copy link
Author

I was able to workaround this issue

@saulo-okada-zs saulo-okada-zs closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
@mrbrentkelly
Copy link

I'm experiencing this behavior as well (so might be worth re-opening this issue). What I'm noticing is if I want to exclude the __tests__ directory at any location in my application directory tree via **/!(__tests__)/*, the plugin doesn't work correctly. It will still show linting errors for nested __tests__ directories.

I've been able to work around it by moving this rule to the overrides eslint configuration and excluding __tests__ in the files property...

"overrides": [
  {
    "plugins": ["check-file"],
    "files": ["src/**/!(__tests__)/*"],
    "rules": {
      "check-file/folder-naming-convention": ["error", { 
        "**/*": "KEBAB_CASE" 
      }]
    }
  },

@JacquesBonet3
Copy link

JacquesBonet3 commented Apr 28, 2024

You have to write like that:

'check-file/folder-naming-convention': ['error', { 'src/**/!(__tests__)': 'XXX_CASE' }],

where XXX is CAMEL, KEBAB, ...

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

No branches or pull requests

4 participants