pacocoursey / next-unused

Find unused files in your Next.js projects
421 stars 15 forks source link

Library reports all files are unused #20

Open eloisetaylor5693 opened 2 years ago

eloisetaylor5693 commented 2 years ago

This library reports all component files are unused on our project.

Folder structure:

package.json
├─ src
    ├─ pages/
    |    └─ homepage.tsx
    └─ components/
         ├─ button.tsx
         └─ heroSection.tsx

config:

  "next-unused": {
    "alias": {
      "@companyname": "src/"
    },
    "include": [
      "src/components"
    ],
    "exclude": [],
    "entrypoints": [
      "src/pages"
    ]
  }

we use a mix of import styles in our components:

import Button from '@companyName/components/atoms/Button';
import Button from './Button';
eloisetaylor5693 commented 2 years ago

After exploring past issues I modified my config, But components which reference other components are showing in the results.

Eg a title component might be used in a hero section component

  "next-unused": {
    "debug": true,
    "alias": {
      "components": "src/components/"
    },
    "include": [
      "src/pages",
      "src/components"
    ],
    "exclude": [
      ".tests."
    ],
    "entrypoints": [
      "src/pages"
    ]
  }
lucasvazq commented 2 years ago

Did you try eslint:no-unused-modules?

I use this config:

"import/no-unused-modules": [
  1,
  {
    "missingExports": true,
    "unusedExports": true,
    "ignoreExports": [
      "src/pages",
      "src/scripts",
      "*.d.ts"
    ]
  }
],