- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 639
Detect dead code and unused dependencies #1687
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
Changes from all commits
c3ef192
              7391ded
              5ecccd4
              d2560f8
              b766f50
              5a461fe
              5e2109b
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -15,3 +15,5 @@ node_package/webpack.config.js | |
| **/public/packs*/* | ||
| gen-examples | ||
| bundle/ | ||
| # Can't get it working in CI | ||
| knip.ts | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -4,6 +4,7 @@ extends: | |
| - prettier/react | ||
|  | ||
| plugins: | ||
| - import | ||
| - prettier | ||
|  | ||
| globals: | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import type { KnipConfig } from 'knip'; | ||
|  | ||
| const config: KnipConfig = { | ||
| // ! at the end means files are used in production | ||
| workspaces: { | ||
| '.': { | ||
| entry: ['node_package/src/ReactOnRails.ts!', 'node_package/src/ReactOnRails.node.ts!'], | ||
| project: ['node_package/src/**/*.[jt]s!', 'node_package/tests/**/*.[jt]s'], | ||
| babel: { | ||
| config: ['node_package/babel.config.js'], | ||
| }, | ||
| ignoreBinaries: [ | ||
| // Knip fails to detect it's declared in devDependencies | ||
| 'nps', | ||
| // local scripts | ||
| 'node_package/scripts/.*', | ||
| ], | ||
| ignoreDependencies: [ | ||
| // Required for TypeScript compilation, but we don't depend on Turbolinks itself. | ||
| '@types/turbolinks', | ||
| // used in package-scripts.yml | ||
| 'concurrently', | ||
| // The Knip ESLint plugin fails to detect these are transitively required by a config, | ||
| // though we don't actually use its rules anywhere. | ||
| 'eslint-plugin-jsx-a11y', | ||
| 'eslint-plugin-react', | ||
| ], | ||
| }, | ||
| 'spec/dummy': { | ||
| entry: [ | ||
| 'app/assets/config/manifest.js!', | ||
| 'client/app/packs/**/*.js!', | ||
| // Not sure why this isn't detected as a dependency of client/app/packs/server-bundle.js | ||
| 'client/app/generated/server-bundle-generated.js!', | ||
| 'spec/fixtures/automated_packs_generation/**/*.js{x,}', | ||
| 'config/webpack/{production,development,test}.js', | ||
| // Declaring this as webpack.config instead doesn't work correctly | ||
| 'config/webpack/webpack.config.js', | ||
| ], | ||
| project: ['**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}!', 'config/webpack/*.js'], | ||
| paths: { | ||
| 'Assets/*': ['client/app/assets/*'], | ||
| }, | ||
| ignoreBinaries: [ | ||
| // Has to be installed globally | ||
| 'yalc', | ||
| // Local binaries | ||
| 'bin/.*', | ||
| ], | ||
| ignoreDependencies: [ | ||
| // Knip thinks it can be a devDependency, but it's supposed to be in dependencies. | ||
| '@babel/runtime', | ||
| // There's no ReScript plugin for Knip | ||
| '@rescript/react', | ||
| // The Babel plugin fails to detect it | ||
| 'babel-plugin-transform-react-remove-prop-types', | ||
| // This one is weird. It's long-deprecated and shouldn't be necessary. | ||
| // Probably need to update the Webpack config. | ||
| 'node-libs-browser', | ||
| // The below dependencies are not detected by the Webpack plugin | ||
| // due to the config issue. | ||
| 'css-loader', | ||
| 'expose-loader', | ||
| 'file-loader', | ||
| 'imports-loader', | ||
| 'mini-css-extract-plugin', | ||
| 'null-loader', | ||
| 'sass', | ||
| 'sass-loader', | ||
| 'sass-resources-loader', | ||
| 'style-loader', | ||
| 'url-loader', | ||
| ], | ||
| }, | ||
| }, | ||
| }; | ||
|  | ||
| export default config; | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -9,6 +9,7 @@ declare global { | |
| } | ||
| } | ||
|  | ||
| /** @internal Exported only for tests */ | ||
| export function consoleReplay(customConsoleHistory: typeof console['history'] | undefined = undefined, numberOfMessagesToSkip: number = 0): string { | ||
| 
      Comment on lines
    
      +12
     to 
      13
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate console level to prevent XSS. The function accepts msg.level without validation, which could lead to XSS if console.history is tampered with. Consider validating against allowed console methods. +const ALLOWED_CONSOLE_METHODS = new Set(['error', 'log', 'debug']);
+
 export function consoleReplay(customConsoleHistory: typeof console['history'] | undefined = undefined, numberOfMessagesToSkip: number = 0): string {
 | ||
| // console.history is a global polyfill used in server rendering. | ||
| const consoleHistory = customConsoleHistory ?? console.history; | ||
|  | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.