deno icon indicating copy to clipboard operation
deno copied to clipboard

Deno lint ignores the `ignore` and `exclude` options

Open viktormarinho opened this issue 1 year ago • 10 comments

Version: Deno 2.0.0

I'm using deno in a workspace that includes a npm package project/packages/ui which is a collection of React components, that use tailwind. In this package, i have a globals.css file that is not valid for the default Deno CSS linter, since i have a setup that uses postcss to process it (for tailwind) etc.

Problem is, i cannot seem to ignore this file in any way. I've tried using --ignore, putting it inside lint: { exclude: [*.css] } inside a deno.json file at the root of the project and at the package, and using a comment at the top of the css file with deno-lint-ignore-file.

Besides all that, deno lint keeps breaking on this file, trying to check it.

viktormarinho avatar Oct 16 '24 13:10 viktormarinho

deno lint doesn't try to read CSS files, it's only meant for JS/TS/JSX/TSX files.

Could you please paste an output from your terminal?

bartlomieju avatar Oct 16 '24 13:10 bartlomieju

@bartlomieju Yeah sure, here it is

➜  project git:(6ef580b) deno lint .
error: The module's source code could not be parsed: Expected ';', '}' or <eof> at file:///Users/viktor/repos/project/packages/ui/globals.css:5:13

  @layer base {
              ~

viktormarinho avatar Oct 16 '24 13:10 viktormarinho

Maybe that's happening because the deno.jsonc file at this package exports the globals.css file. When i delete it, this stops happening.

viktormarinho avatar Oct 16 '24 13:10 viktormarinho

Can you please paste the contents of deno.jsonc file?

bartlomieju avatar Oct 16 '24 13:10 bartlomieju

Something that could maybe be causing problems here is that, this package includes both a deno.jsonc file and a package.json file. I included the deno.jsonc just because without it deno could not find the types of the package being imported. (I have another issue related to that tho, #26306 )

{
  "name": "@project/ui",
  "exports": {
    "./lib/utils.ts": "./src/lib/utils.ts",
    "./hooks/use-toast.ts": "./src/hooks/use-toast.ts",
    "./components/alert-dialog.tsx": "./src/components/alert-dialog.tsx",
    "./components/avatar.tsx": "./src/components/avatar.tsx",
    "./components/badge.tsx": "./src/components/badge.tsx",
    "./components/button.tsx": "./src/components/button.tsx",
    "./components/command.tsx": "./src/components/command.tsx",
    "./components/dialog.tsx": "./src/components/dialog.tsx",
    "./components/drawer.tsx": "./src/components/drawer.tsx",
    "./components/form.tsx": "./src/components/form.tsx",
    "./components/input.tsx": "./src/components/input.tsx",
    "./components/label.tsx": "./src/components/label.tsx",
    "./components/separator.tsx": "./src/components/separator.tsx",
    "./components/spinner.tsx": "./src/components/spinner.tsx",
    "./components/switch.tsx": "./src/components/switch.tsx",
    "./components/table.tsx": "./src/components/table.tsx",
    "./components/tabs.tsx": "./src/components/tabs.tsx",
    "./components/toast.tsx": "./src/components/toast.tsx",
    "./components/toaster.tsx": "./src/components/toaster.tsx",
    "./components/tooltip.tsx": "./src/components/tooltip.tsx",
    "./postcss.config.mjs": "./postcss.config.mjs",
    "./tailwind.config.ts": "./tailwind.config.ts",
    "./globals.css": "./globals.css"
  }
}

viktormarinho avatar Oct 16 '24 13:10 viktormarinho

As a workaround, disabling the no-slow-types rule might fix the issue:

// deno.jsonc
{
  "lint": {
    "rules": {
      "exclude": ["no-slow-types"]
    }
  },
  // ...
}

Probably what's happening here is that lint rule is analyzing all the exports of the package.

dsherret avatar Oct 16 '24 14:10 dsherret

As a workaround, disabling the no-slow-types rule might fix the issue:

// deno.jsonc
{
  "lint": {
    "rules": {
      "exclude": ["no-slow-types"]
    }
  },
  // ...
}

Probably what's happening here is that lint rule is analyzing all the exports of the package.

Still happens with no-slow-types disabled

viktormarinho avatar Oct 16 '24 14:10 viktormarinho

This is also a bug with deno fmt. I have a workspace setup where I have this fmt config:

  "fmt": {
    "include": ["*.ts", "*.tsx"],
    "exclude": ["*.d.ts", "./server/*"],
    "lineWidth": 120
  },

This still tries to process JS, CSS and even JSON files. However, when I also exclude the directory which contains those files (my Next JS build directory), it works fine. The include statement just shouldn't work with those files to begin with.

mintydev789 avatar Oct 23 '24 13:10 mintydev789

I was able to reproduce it with these three files:

// deno.json
{
    "name": "@project/ui",
    "exports": {
        "./main.ts": "./main.ts",
        "./globals.css": "./globals.css"
    }
}
// main.ts
// globals.css
body {
    color: "red";
}

Run deno lint:

error: The module's source code could not be parsed: Expected ';', '}' or <eof> at file:///Users/ib/dev/scratch_lint_css/globals.css:1:6

  body {
       ~

Indeed adding lint.exclude doesn't make the problem go away. Removing main.ts from "exports" makes the error go away.

I'll dig into this

bartlomieju avatar Oct 28 '24 12:10 bartlomieju

Found one more problem that might be a separate issue. Running deno lint <some file> in the project from the above comment always triggers this error, even though it should only lint one specific file.

bartlomieju avatar Oct 29 '24 23:10 bartlomieju

I used the --no-config flag to avoid having lint try importing CSS files.

safaaleigh avatar Dec 18 '24 20:12 safaaleigh