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

Ignore rules with sub-projects don't seem to work #469

Closed
vikaspotluri123 opened this issue Apr 29, 2020 · 8 comments
Closed

Ignore rules with sub-projects don't seem to work #469

vikaspotluri123 opened this issue Apr 29, 2020 · 8 comments
Labels

Comments

@vikaspotluri123
Copy link

Hey 👋

I'm working on a project that's written in JS, but has a submodule that uses typescript. I'm trying to bump xo from 0.25.3 to 0.30.0, but I'm running into a bunch of errors.

The submodule is rooted at lib/frontend/client and no matter what I set in the ignore flag, I get a bunch of errors from the compiled output of the submodule:

Partial screenshot of terminal output

image

I've tried the following combinations:
--ignore lib, --ignore lib/frontend/client, --ignore lib/frontend/client/\*\*, --ignore lib/frontend/client/\*\*/\*

I had the ignore pattern "lib/frontend/client/**/*.js" in my package config for 0.25.3 which was fully functional, and I changed it to "lib/frontend/client/**/*" for 0.30.0 to reflect the added typescript support, but that's still failing. I ran into this issue while trying to bump xo to 0.28.x and 0.29.x as well.

I checked the docs, and didn't see anything about this, and I couldn't find any issues with a similar problem.

I also see a bunch of these warnings at the end:

  lib/frontend/client/dist/out-tsc/src/app/app.module.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

  lib/frontend/client/dist/out-tsc/src/app/app.component.spec.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

  lib/frontend/client/dist/out-tsc/src/app/app.component.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

  lib/frontend/client/dist/out-tsc/src/app/app-routing.module.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

  lib/frontend/client/dist/out-tsc/src/test.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

  lib/frontend/client/dist/out-tsc/src/polyfills.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

  lib/frontend/client/dist/out-tsc/src/index.js:undefined:undefined
  ✖    0:0    Parsing error: File {root}/tsconfig.json not found.

Let me know if you'd like any more info! Thanks

@vikaspotluri123 vikaspotluri123 changed the title Command Line seems to not follow ignore rules with sub-projects Ignore rules with sub-projects don't seem to work Apr 29, 2020
@sindresorhus
Copy link
Member

Can you share the xo config in your package.json?

@vikaspotluri123
Copy link
Author

Here it is:

  "xo": {
    "ignores": [
      "lib/frontend/client/**/*"
    ],
    "extends": "plugin:mocha/recommended",
    "plugins": [
      "mocha"
    ],
    "rules": {
      "func-names": [
        "error",
        "as-needed"
      ],
      "no-use-extend-native/no-use-extend-native": "off",
      "func-name-matching": "off",
      "no-console": "error"
    },
    "overrides": [
      {
        "files": "test/**/*.js",
        "envs": [
          "node",
          "mocha"
        ],
        "global": [
          "expect",
          "sinon",
          "testUtils"
        ],
        "rules": {
          "func-names": "off",
          "prefer-arrow-callback": "off",
          "no-unused-expressions": "off"
        }
      },
      {
        "files": "_commands/**/*.js",
        "rules": {
          "unicorn/no-process-exit": "off",
          "no-console": "off"
        }
      },
      {
        "files": "scripts/**/*.js",
        "rules": {
          "no-console": "off"
        }
      }
    ]
  }

@sindresorhus
Copy link
Member

This definitely looks like a bug in XO's TypeScript handling. I'm not sure why it's trying to resolve a tsconfig.json file for JS files.

// @pvdlg

@vikaspotluri123
Copy link
Author

vikaspotluri123 commented May 3, 2020

Please let me know if there's anything you need from me! I tried to create a minimal use case, but I'm not sure what's causing the issue. I'm happy to run any modified versions to debug or fix the issue test that the issue is fixed 😄

@Bauke
Copy link

Bauke commented Aug 2, 2020

Hi, I think I just came across this same problem but not with TypeScript, just a submodule with an older version of XO. Running xo outputs that certain rule definitions aren't found:

  submodules/userstyles/source/utilities.js:1:1
  ✖  1:1  Definition for rule unicorn/better-regex was not found.    unicorn/better-regex
  ✖  1:1  Definition for rule node/no-mixed-requires was not found.  node/no-mixed-requires
  ✖  1:1  Definition for rule node/no-new-require was not found.     node/no-new-require
  ✖  1:1  Definition for rule node/no-path-concat was not found.     node/no-path-concat

  submodules/userstyles/source/index.js:1:1
  ✖  1:1  Definition for rule unicorn/better-regex was not found.    unicorn/better-regex
  ✖  1:1  Definition for rule node/no-mixed-requires was not found.  node/no-mixed-requires
  ✖  1:1  Definition for rule node/no-new-require was not found.     node/no-new-require
  ✖  1:1  Definition for rule node/no-path-concat was not found.     node/no-path-concat

The root config, running ^0.32.1:

"xo": {
  "ignores": [
    "submodules/**/*.js"
  ],
  "prettier": true,
  "rules": {
    "no-await-in-loop": "off"
  },
  "space": true
}

The submodule config, running ^0.27.2:

"xo": {
  "prettier": true,
  "rules": {
    "no-await-in-loop": "off"
  },
  "space": true
}

This will probably be "fixed" for me after I update the submodule's XO to the same version, but I figured I'd comment here anyway since I was expecting the files to be ignored completely.

Edit: Confirmed my suspicion that updating the submodule XO "fixes" it.

@vikaspotluri123
Copy link
Author

vikaspotluri123 commented Oct 8, 2020

@sindresorhus I've narrowed the issue to config files - when globby generates configFiles, this is the output (removed the config value for brevity):

[
  {
    // This config is the one I want to be used (contains `ignores: ["lib/frontend/**/*"]`)
    filepath: "{root}/package.json",
  },
  {
    // This is a discovered config that should be ignored
    filepath: "{root}/lib/frontend/client/package.json",
  },
  {
    // This is a discovered config that should be ignored
    filepath: "{root}/.../out-tsc/package.json",
  },
]

So lib/frontend/client is "force" included because globby found a package.json in it.

How do you suggest the issue be fixed (either from an XO side, or flag / config side)? I'm more than happy to take a stab at creating a PR if needed. Do you know if there are other config issues that this could be similar to?


Relevant lines:

xo/index.js

Lines 100 to 105 in a5ff341

const configFiles = (await Promise.all(
(await globby(
CONFIG_FILES.map(configFile => `**/${configFile}`),
{ignore: DEFAULT_IGNORES, gitignore: true, cwd: options.cwd}
)).map(async configFile => configExplorer.load(path.resolve(options.cwd, configFile)))
)).filter(Boolean);

@vikaspotluri123
Copy link
Author

@sindresorhus wanted to follow up since it's been a bit 😄

The concise version of the issue is this:

It's not possible to ignore subdirectories that contain a package.json file (with xo overrides) in the root xo config

Is this something that needs to be fixed in the config or in xo? If it's an xo issue, I'd be more than happy to create a PR to fix it if you point me in the right direction

@vikaspotluri123
Copy link
Author

Looks like this was fixed in the latest release(s), I'm guessing because of #534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants