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

How to exclude all directories except one? #1758

Closed
dshemin opened this issue Sep 24, 2021 · 11 comments
Closed

How to exclude all directories except one? #1758

dshemin opened this issue Sep 24, 2021 · 11 comments

Comments

@dshemin
Copy link

dshemin commented Sep 24, 2021

I have a directory with bunch of translation files like

/de_DE
/el_GR
/en_US
and etc.

I want to exclude all files except en_US. Of course I can specify them all in ignorePaths section, but can I do it better?

@Jason3S
Copy link
Collaborator

Jason3S commented Sep 28, 2021

@dshemin,

Are you asking about command line or configuration?

Command Line

Exclude them:

cspell --exclude "de_DE/**" --exclude "el_GR/**" "**"

Include Only en_US

cspell "en_US/**"

Configuration

There are three places that impact which files are checked:

  1. files -- to only include the files you want.
    cspell.config.yaml

    files:
        - docs/en_US/**
  2. ignorePaths - to exclude the files you do not want.
    cspell.config.yaml

    ignorePaths:
        - docs/de_DE/**
        - docs/el_GR/**
  3. Overrides - to tell the spell checkers to treat these files differently. Note: overrides are applied after the list of files have been collected.
    cspell.config.yaml

    overrides:
        - filename: docs/**
          enable: false
        - filename: docs/en_US/**
          enable: true

You can also use overrides to have cspell use a different dictionary or language locale.

Needed dictionaries:

Example: cspell.json

    "import": [
        "@cspell/dict-de-de/cspell-ext.json",
        "@cspell/dict-el/cspell-ext.json"
    ],
    "overrides": [
        {
            "filename": "**/de_DE/**",
            "language": "en,de"
        },
        {
            "filename": "**/el_GR/**",
            "language": "en,el"
        }
    ]

@dshemin
Copy link
Author

dshemin commented Sep 28, 2021

I'm talking about configuration. Let me explain a little bit more about my issue.
I have a directory with translation located in I10n with the next structure:

I10n/
    de_DE/
    el_GR/
    en_US/

I want to exclude all files from the I10n except files located in the en_US directory. As far as I understand I can write the next config to achieve that:

files:
    - I10n/en_US/**

ignorePaths:
    - I10n/***

I'm right?

@Jason3S
Copy link
Collaborator

Jason3S commented Sep 28, 2021

After writing the response, I realized you might be trying to do the following:

ignorePaths:
  - "docs/**"
  - "!docs/en_US/**"

That is not supported by the glob library. See: Does not match for negative ignore · Issue #409 · isaacs/node-glob.

@Jason3S
Copy link
Collaborator

Jason3S commented Sep 28, 2021

@dshemin,

Using overrides will do what you want:

files: 
    - I10n/**
overrides:
    - filename: I10n/**
      enable: false
    - filename: I10n/en_US/**
      enable: true

@dshemin
Copy link
Author

dshemin commented Sep 28, 2021

Thanks! I will try it.

@Jason3S
Copy link
Collaborator

Jason3S commented Sep 28, 2021

Note: overrides are applied in order. So, reversing the order of the overrides will not work.

@Jason3S
Copy link
Collaborator

Jason3S commented Sep 28, 2021

This also works:

files:
  - I10n/**
overrides:
  - filename:
      - I10n/**
      - '!I10n/en_US/**'
    enable: false

@dshemin
Copy link
Author

dshemin commented Sep 28, 2021

Is the files property required in the last example?

@Jason3S
Copy link
Collaborator

Jason3S commented Sep 28, 2021

Is the files property required in the last example?

No it isn't.

@Jason3S Jason3S changed the title Can't exclude all directories except one How to exclude all directories except one? Oct 6, 2021
@Jason3S Jason3S added the FAQ label Oct 6, 2021
@Jason3S
Copy link
Collaborator

Jason3S commented Oct 6, 2021

I'm going to close this for now. If something is not working as you expect, please feel free to create a new issue and refer to this one.

@Jason3S Jason3S closed this as completed Oct 6, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2021

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants