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

Add configuration to unused files #6782

Merged
merged 15 commits into from
Jun 27, 2024

Conversation

yenienserrano
Copy link
Member

@yenienserrano yenienserrano commented Jun 19, 2024

Description

Add eslint settings to know which export is not being used and to identify unused files.

Tasks

  • Add linter rule to detect unused exports
  • Add knip tool and script to detect unused files
  • Fix package scripts for main plugin related to lint the code
  • Fix package script form main plugin related to fomat the code with prettier
  • Remove unused files
  • Move some imports to import from index.{js,ts} instead of specific file

Issues Resolved

Evidence

Knip
yarn knip
yarn run v1.22.22
$ knip --files
✂️  Excellent, Knip found no issues.
✨  Done in 4.47s.
Details
yarn lint:public | grep 'import/no-unused-modules'
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found      import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found                          import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found         import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1    error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found                                                                                                                                                                                                                                                                                                                                                                                        import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
    1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
     1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1    error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1    error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
  1:1  error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
   1:1   error  Definition for rule 'import/no-unused-modules' was not found  import/no-unused-modules
error Command failed with exit code 1.

Test

  1. Run the yarn knip.
  2. In the main plugin you should not have any unused files.
  3. Add a file that is not used anywhere and re-run the command
  4. The file should appear as unused
  5. Smoke test of the application
  6. Everything should work as it should

Check List

  • All tests pass
    • yarn test:jest
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

plugins/main/package.json Outdated Show resolved Hide resolved
@Desvelao Desvelao linked an issue Jun 24, 2024 that may be closed by this pull request
1 task
@yenienserrano yenienserrano marked this pull request as ready for review June 24, 2024 20:43
plugins/main/package.json Outdated Show resolved Hide resolved
@JuanGarriuz JuanGarriuz self-requested a review June 25, 2024 14:41
@JuanGarriuz
Copy link
Member

Test

Knip no issues 🟢

yarn knip                             
yarn run v1.22.19
warning Skipping preferred cache folder "/home/node/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-1000".
$ knip --files
✂️  Excellent, Knip found no issues.
Done in 8.39s.

Knip issues 🟢

yarn knip
yarn run v1.22.19
warning Skipping preferred cache folder "/home/node/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-1000".
$ knip --files
public/react-services/interfaces/no-export.js
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@Desvelao
Copy link
Member

🟢 Test

In the main plugin you should not have any unused files:

node@osd:~/kbn/plugins/wazuh$ yarn knip
yarn run v1.22.19
warning Skipping preferred cache folder "/home/node/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-1000".
$ knip --files
✂️  Excellent, Knip found no issues.
Done in 11.62s.

Adding a unused file:

node@osd:~/kbn/plugins/wazuh$ yarn knip 
yarn run v1.22.19
warning Skipping preferred cache folder "/home/node/.cache/yarn" because it is not writable.
warning Selected the next writable cache folder in the list, will be "/tmp/.yarn-cache-1000".
$ knip --files
common/unused_file.ts
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Copy link
Contributor

Wazuh Check Updates plugin code coverage (Jest) test % values
Statements 76.44% ( 172 / 225 )
Branches 58.65% ( 61 / 104 )
Functions 61.7% ( 29 / 47 )
Lines 76.44% ( 172 / 225 )

Copy link
Contributor

Wazuh Core plugin code coverage (Jest) test % values
Statements 45.96% ( 399 / 868 )
Branches 41.97% ( 157 / 374 )
Functions 44.01% ( 136 / 309 )
Lines 46.16% ( 397 / 860 )

Copy link
Contributor

Main plugin code coverage (Jest) test % values
Statements 13.65% ( 3993 / 29233 )
Branches 9.1% ( 1743 / 19149 )
Functions 13.36% ( 944 / 7065 )
Lines 13.84% ( 3890 / 28093 )

Copy link
Member

@Desvelao Desvelao left a comment

Choose a reason for hiding this comment

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

LGTM!

@Desvelao Desvelao merged commit 06f52c2 into 4.9.0 Jun 27, 2024
4 checks passed
@Desvelao Desvelao deleted the enhancement/6748-identify-unused-files branch June 27, 2024 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Identify unused files
3 participants