Skip to content

Conversation

@beaussan
Copy link
Contributor

@beaussan beaussan commented Mar 11, 2024

This pr introduce a knip config for this repo. Setting up knip with an Nx Integrated workspace requires a bit more trickery than a regular npm workspace, so I created a library for it. The library is still in it's early form, but I will maintain and evolve it's api here if I make any breaking changes.

Source for the library can be found here.

To see the generated knip config, you can run DEBUG=true npm run knip, it's traversing Nx's graph of library, executors and configuration to infer a knip config dynamically.

Running knip on this repo yeild the following output :

Unused files (4)
packages/cli/code-pushup.config.mock.ts
packages/plugin-lighthouse/src/index.ts
testing/test-utils/src/lib/fixtures/configs/code-pushup.config.js
testing/test-utils/src/lib/fixtures/configs/code-pushup.empty.config.js
Unused devDependencies (15)
@nodelib/fs.walk                       package.json
@trivago/prettier-plugin-sort-imports  package.json
@types/benchmark                       package.json
benchmark                              package.json
commitlint-plugin-tense                package.json
conventional-changelog-angular         package.json
eslint-plugin-jsx-a11y                 package.json
eslint-plugin-react                    package.json
eslint-plugin-react-hooks              package.json
fast-glob                              package.json
glob                                   package.json
globby                                 package.json
jsonc                                  package.json
ngx-deploy-npm                         package.json
tsx                                    package.json
Unlisted dependencies (16)
jsonc-eslint-parser                   .eslintrc.json                           
@commitlint/types                     commitlint.config.js                     
jsonc-eslint-parser                   e2e/cli-e2e/.eslintrc.json               
jsonc-eslint-parser                   packages/cli/.eslintrc.json              
jsonc-eslint-parser                   packages/core/.eslintrc.json             
jsonc-eslint-parser                   packages/models/.eslintrc.json           
jsonc-eslint-parser                   packages/nx-plugin/.eslintrc.json        
jsonc-eslint-parser                   packages/plugin-coverage/.eslintrc.json  
jsonc-eslint-parser                   packages/plugin-eslint/.eslintrc.json    
jsonc-eslint-parser                   packages/plugin-lighthouse/.eslintrc.json
jsonc-eslint-parser                   packages/utils/.eslintrc.json            
jsonc-eslint-parser                   testing/test-setup/.eslintrc.json        
jsonc-eslint-parser                   testing/test-utils/.eslintrc.json        
@nx/eslint/src/executors/lint/schema  tools/eslint-to-code-pushup.mjs          
minimatch                             tools/eslint-to-code-pushup.mjs          
tslib                                 tsconfig.base.json
Unused exports (24)
renderUploadAutorunHint                 function  packages/cli/src/lib/collect/collect-command.ts:45:17           
yargsPersistConfigOptionsDefinition     function  packages/cli/src/lib/implementation/core-config.options.ts:17:17
yargsUploadConfigOptionsDefinition      function  packages/cli/src/lib/implementation/core-config.options.ts:37:17
singletonUiInstance                     unknown   packages/cli/src/lib/implementation/logging.ts:8:12             
duplicateRefsInCategoryMetricsErrorMsg  function  packages/models/src/lib/category-config.ts:54:17                
unrefinedCoreConfigSchema               unknown   packages/models/src/lib/core-config.ts:11:14                    
refineCoreConfig                        function  packages/models/src/lib/core-config.ts:32:17                    
groupMetaSchema                         unknown   packages/models/src/lib/group.ts:20:14                          
weightSchema                            unknown   packages/models/src/lib/implementation/schemas.ts:132:14        
descriptionSchema                       unknown   packages/models/src/lib/implementation/schemas.ts:40:14         
docsUrlSchema                           unknown   packages/models/src/lib/implementation/schemas.ts:49:14         
titleSchema                             unknown   packages/models/src/lib/implementation/schemas.ts:55:14         
pluginDataSchema                        unknown   packages/models/src/lib/plugin-config.ts:30:14                  
coverageTypeSchema                      unknown   packages/plugin-coverage/src/lib/config.ts:3:14                 
coverageResultSchema                    unknown   packages/plugin-coverage/src/lib/config.ts:6:14                 
WORKDIR                                 unknown   packages/plugin-eslint/src/lib/runner/index.ts:9:14             
NoExportError                           class     packages/utils/src/lib/file-system.ts:78:14                     
messageStyles                           unknown   packages/utils/src/lib/progress.ts:13:14                        
h                                       function  packages/utils/src/lib/reports/md/headline.ts:13:17             
h4                                      function  packages/utils/src/lib/reports/md/headline.ts:25:17             
h5                                      function  packages/utils/src/lib/reports/md/headline.ts:29:17             
h6                                      function  packages/utils/src/lib/reports/md/headline.ts:33:17             
GroupRefInvalidError                    class     packages/utils/src/lib/reports/scoring.ts:10:14                 
throwIsNotPresentError                  function  packages/utils/src/lib/reports/utils.ts:233:17
Unused exported types (7)
CliUi                 type  packages/cli/src/lib/implementation/logging.ts:5:13 
GroupMeta             type  packages/models/src/lib/group.ts:26:13              
LighthouseCliOptions  type  packages/plugin-lighthouse/src/lib/utils.ts:11:13   
FontStyle             type  packages/utils/src/lib/reports/md/font-style.ts:8:13
Hierarchy             type  packages/utils/src/lib/reports/md/headline.ts:2:13  
Order                 type  packages/utils/src/lib/reports/md/list.ts:1:13      
ScoredCategoryConfig  type  packages/utils/src/lib/reports/types.ts:9:13
Duplicate exports (2)
addToProjectGenerator, default  packages/nx-plugin/src/generators/configuration/generator.ts
initGenerator, default          packages/nx-plugin/src/generators/init/generator.ts

@beaussan beaussan marked this pull request as ready for review March 11, 2024 07:58
@BioPhoton
Copy link
Collaborator

Nice idea!!

If you would create an example plugin under examples/plugins/knip similar to the other examples that would be amazing and should be straight forward.

@nx-cloud
Copy link

nx-cloud bot commented Mar 12, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 438aab6. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected:e2e --parallel=3
✅ Successfully ran 5 targets

Sent with 💌 from NxCloud.

@beaussan beaussan requested a review from BioPhoton as a code owner March 13, 2024 12:24
@github-actions github-actions bot added 📖 Project documentation improvements or additions to the project documentation 🔬 testing writing tests labels Mar 13, 2024
@BioPhoton
Copy link
Collaborator

I tried to directly execute the core knip logic main:

export function runnerFunction(options: RunnerOptions) {
  const {
    cwd,
    isIncludeEntryExports = false,
    isIsolateWorkspaces = false,
    isProduction = false,
    isStrict = false,
    isFix = false,
    fixTypes = [],
    tags = [[''], ['']] as Tags,
    isNoGitIgnore = true,
  } = options;

  return async (): Promise<AuditOutputs> => {
    const kinpReport = await main({
      fixTypes,
      cwd: cwd || process.cwd(),
      tags,
      gitignore: isNoGitIgnore,
      tsConfigFile: '',
      isShowProgress: false,
      isStrict,
      isFix,
      isIncludeEntryExports,
      isIsolateWorkspaces,
      isProduction,
    });

    return knipToCpReport(kinpReport);
  }
}

I get the following error: Unexpected argument 'collect'. This command does not take positional arguments

@github-actions github-actions bot removed the 📖 Project documentation improvements or additions to the project documentation label Mar 15, 2024
@github-actions github-actions bot removed the 🔬 testing writing tests label Mar 15, 2024
@github-actions github-actions bot removed the 🧩 cli label Mar 15, 2024
@BioPhoton
Copy link
Collaborator

As the example plugin is out of here now we could defined a scope for this one.

I believe to be useful it should at least show no false positives.

BioPhoton
BioPhoton previously approved these changes Apr 17, 2024
Copy link
Collaborator

@BioPhoton BioPhoton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@github-actions github-actions bot added the 📖 Project documentation improvements or additions to the project documentation label Apr 22, 2024
@matejchalk matejchalk merged commit f255504 into code-pushup:main Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📖 Project documentation improvements or additions to the project documentation 🛠️ tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants