Closed asteriscos closed 4 months ago
Some of the tools I found and have been researching are:
no-unused-modules
.The deadfile and knip work in a similar way, you have to pass them the most global file and from that file you will see which files are never imported. The files that it says are never used should be checked because it gives a strange answer.
The no-unused-modules
is to add it to linter and it tells you which files have an export and are not being imported anywhere else, it is interesting but actually we should fix the long standing linter problems before adding new problems.
import/no-unused-modules
I was testing the import/no-unused-modules
rule for the linter and provided by the eslint-plugin-import
package.
eslint-plugin-import
as a dev dependency:yarn add -D eslint-plugin-import
.eslintrc.json
{
...
"import/no-used-modules": [1, {"unusedExports:true"}]
}
mport/no-unused-modules
rule:yarn lint | grep 'import/no-unused-modules'
Test in 4.8.1 on the
main
plugin
node@osd:~/kbn/plugins/wazuh$ yarn lint | grep 'import/no-unused-modules'
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".
34:1 warning exported declaration 'WzSampleDataProvider' not used within other modules import/no-unused-modules
14:1 warning exported declaration 'default' not used within other modules import/no-unused-modules
1172:1 warning exported declaration 'default' not used within other modules import/no-unused-modules
18:1 warning exported declaration 'emptyFieldHandler' not used within other modules import/no-unused-modules
12:1 warning exported declaration 'EventsSelectedFiles' not used within other modules import/no-unused-modules
5:1 warning exported declaration 'ProgressChart' not used within other modules import/no-unused-modules
1:10 warning exported declaration 'EuiSuggestInput' not used within other modules import/no-unused-modules
3:10 warning exported declaration 'EuiSuggestItem' not used within other modules import/no-unused-modules
5:10 warning exported declaration 'EuiSuggest' not used within other modules import/no-unused-modules
19:1 warning exported declaration 'COLORS' not used within other modules import/no-unused-modules
26:1 warning exported declaration 'DISPLAYS' not used within other modules import/no-unused-modules
14:1 warning exported declaration 'apiRequestList' not used within other modules import/no-unused-modules
28:1 warning exported declaration 'VisualizeTopMenu' not used within other modules import/no-unused-modules
58:1 warning exported declaration 'WzMenu' not used within other modules import/no-unused-modules
28:1 warning exported declaration 'TestConfiguration' not used within other modules import/no-unused-modules
26:1 warning exported declaration 'ToolsWelcomeCards' not used within other modules import/no-unused-modules
12:1 warning exported declaration 'colors' not used within other modules import/no-unused-modules
30:1 warning exported declaration 'FilesInGroupTable' not used within other modules import/no-unused-modules
121:1 warning exported declaration 'WzConfigurationActiveResponseActiveResponseAgent' not used within other modules import/no-unused-modules
68:1 warning exported declaration 'default' not used within other modules import/no-unused-modules
70:1 warning exported declaration 'WzSettingsViewer' not used within other modules import/no-unused-modules
78:1 warning exported declaration 'WzConfigurationSettingsHeaderViewer' not used within other modules import/no-unused-modules
41:1 warning exported declaration 'settingsBuilder' not used within other modules import/no-unused-modules
51:1 warning exported declaration 'helpLinksBuilder' not used within other modules import/no-unused-modules
83:1 warning exported declaration 'objectWithoutProperties' not used within other modules import/no-unused-modules
157:1 warning exported declaration 'delay' not used within other modules import/no-unused-modules
91:1 warning exported declaration 'extractMessage' not used within other modules import/no-unused-modules
127:1 warning exported declaration 'handleError' not used within other modules import/no-unused-modules
158:1 warning exported declaration 'checkDaemons' not used within other modules import/no-unused-modules
195:1 warning exported declaration 'makePing' not used within other modules import/no-unused-modules
287:1 warning exported declaration 'restartManager' not used within other modules import/no-unused-modules
309:1 warning exported declaration 'restartCluster' not used within other modules import/no-unused-modules
340:1 warning exported declaration 'restartNode' not used within other modules import/no-unused-modules
365:1 warning exported declaration 'saveConfiguration' not used within other modules import/no-unused-modules
385:1 warning exported declaration 'saveNodeConfiguration' not used within other modules import/no-unused-modules
446:1 warning exported declaration 'validateAfterSent' not used within other modules import/no-unused-modules
68:1 warning exported declaration 'replaceXML' not used within other modules import/no-unused-modules
43:1 warning exported declaration 'WzGroupsOverview' not used within other modules import/no-unused-modules
6:1 warning exported declaration 'default' not used within other modules import/no-unused-modules
27:1 warning exported declaration 'WzReportingOverview' not used within other modules import/no-unused-modules
52:1 warning exported declaration 'WzStatisticsOverview' not used within other modules import/no-unused-modules
26:1 warning exported declaration 'WzStatusAgentInfo' not used within other modules import/no-unused-modules
18:1 warning exported declaration 'WzStatusDaemons' not used within other modules import/no-unused-modules
18:1 warning exported declaration 'WzStatusNodeInfo' not used within other modules import/no-unused-modules
59:1 warning exported declaration 'WzStatusOverview' not used within other modules import/no-unused-modules
20:1 warning exported declaration 'WzStatusStats' not used within other modules import/no-unused-modules
147:1 warning exported declaration 'default' not used within other modules import/no-unused-modules
12:1 warning exported declaration 'WazuhConfig' not used within other modules import/no-unused-modules
18:1 warning exported declaration 'ActionAgents' not used within other modules import/no-unused-modules
19:1 warning exported declaration 'CheckDaemonsStatus' not used within other modules import/no-unused-modules
127:1 warning exported declaration 'showFlyoutLogtest' not used within other modules import/no-unused-modules
138:1 warning exported declaration 'updateDockedLogtest' not used within other modules import/no-unused-modules
13:1 warning exported declaration 'updateConfigurationSection' not used within other modules import/no-unused-modules
56:1 warning exported declaration 'updateSortField' not used within other modules import/no-unused-modules
77:1 warning exported declaration 'updateSortDirection' not used within other modules import/no-unused-modules
140:1 warning exported declaration 'updatePageIndex' not used within other modules import/no-unused-modules
173:1 warning exported declaration 'updateFilters' not used within other modules import/no-unused-modules
180:1 warning exported declaration 'cleanFilters' not used within other modules import/no-unused-modules
186:1 warning exported declaration 'cleanInfo' not used within other modules import/no-unused-modules
50:1 warning exported declaration 'cleanInfo' not used within other modules import/no-unused-modules
13:1 warning exported declaration 'updateMetric' not used within other modules import/no-unused-modules
23:1 warning exported declaration 'queryConfig' not used within other modules import/no-unused-modules
20:3 warning exported declaration 'checkTimestamp' not used within other modules import/no-unused-modules
21:3 warning exported declaration 'healthCheck' not used within other modules import/no-unused-modules
1:1 warning exported declaration 'base64' not used within other modules import/no-unused-modules
13:1 warning exported declaration 'stringToObj' not used within other modules import/no-unused-modules
1317:10 warning exported declaration 'generateAlert' not used within other modules import/no-unused-modules
error Command failed with exit code 1.
If you are using a Docker dev environment, this does not mount the linter configuration, so if you want to check the lint on a plugin, you could copy the linter configuration to the root of the plugin.
plugins
main
.eslintrc.json
...
.eslintrc.json
knip
knip
as a dev dependency:yarn add -D knip
knip
.{
"entry": [
"{public,server,common}/index.{js,ts}",
"{public,server,common}/**/*.test.{js,ts,tsx}"
],
"project": ["**/*.{js,ts,jsx,tsx}", "!test/**/*", "!target/**/*"]
}
example configuration for the
main
plugin
knip
listing the unused filesnpx knip --files
The linter import/no-unused-modules
could ensure the source code does not include unused modules. This could reduce the files on the repository but it requires we use the linter in our development and checks workflow.
For another hand, knip
gets unused files (and more features) that helps to remove unused code. If we decide to add this tool, we could create a script (in the package.json) to run it.
Description
We need to able to identify all unused files in the plugins.
Tasks