|
| 1 | +/** @type {import('dependency-cruiser').IConfiguration} */ |
| 2 | +module.exports = { |
| 3 | + forbidden: [ |
| 4 | + { |
| 5 | + name: 'no-circular', |
| 6 | + severity: 'warn', |
| 7 | + comment: |
| 8 | + 'This dependency is part of a circular relationship. You might want to revise ' + |
| 9 | + 'your solution (i.e. use dependency inversion, make sure the modules have a single responsibility) ', |
| 10 | + from: {}, |
| 11 | + to: { |
| 12 | + circular: true |
| 13 | + } |
| 14 | + }, |
| 15 | + { |
| 16 | + name: 'no-orphans', |
| 17 | + comment: |
| 18 | + "This is an orphan module - it's likely not used (anymore?). Either use it or " + |
| 19 | + "remove it. If it's logical this module is an orphan (i.e. it's a config file), " + |
| 20 | + "add an exception for it in your dependency-cruiser configuration. By default " + |
| 21 | + "this rule does not scrutinize dot-files (e.g. .eslintrc.js), TypeScript declaration " + |
| 22 | + "files (.d.ts), tsconfig.json and some of the babel and webpack configs.", |
| 23 | + severity: 'warn', |
| 24 | + from: { |
| 25 | + orphan: true, |
| 26 | + pathNot: [ |
| 27 | + '(^|/)[.][^/]+[.](?:js|cjs|mjs|ts|cts|mts|json)$', // dot files |
| 28 | + '[.]d[.]ts$', // TypeScript declaration files |
| 29 | + '(^|/)tsconfig[.]json$', // TypeScript config |
| 30 | + '(^|/)(?:babel|webpack)[.]config[.](?:js|cjs|mjs|ts|cts|mts|json)$' // other configs |
| 31 | + ] |
| 32 | + }, |
| 33 | + to: {}, |
| 34 | + }, |
| 35 | + { |
| 36 | + name: 'no-deprecated-core', |
| 37 | + comment: |
| 38 | + 'A module depends on a node core module that has been deprecated. Find an alternative - these are ' + |
| 39 | + "bound to exist - node doesn't deprecate lightly.", |
| 40 | + severity: 'warn', |
| 41 | + from: {}, |
| 42 | + to: { |
| 43 | + dependencyTypes: [ |
| 44 | + 'core' |
| 45 | + ], |
| 46 | + path: [ |
| 47 | + '^v8/tools/codemap$', |
| 48 | + '^v8/tools/consarray$', |
| 49 | + '^v8/tools/csvparser$', |
| 50 | + '^v8/tools/logreader$', |
| 51 | + '^v8/tools/profile_view$', |
| 52 | + '^v8/tools/profile$', |
| 53 | + '^v8/tools/SourceMap$', |
| 54 | + '^v8/tools/splaytree$', |
| 55 | + '^v8/tools/tickprocessor-driver$', |
| 56 | + '^v8/tools/tickprocessor$', |
| 57 | + '^node-inspect/lib/_inspect$', |
| 58 | + '^node-inspect/lib/internal/inspect_client$', |
| 59 | + '^node-inspect/lib/internal/inspect_repl$', |
| 60 | + '^async_hooks$', |
| 61 | + '^punycode$', |
| 62 | + '^domain$', |
| 63 | + '^constants$', |
| 64 | + '^sys$', |
| 65 | + '^_linklist$', |
| 66 | + '^_stream_wrap$' |
| 67 | + ], |
| 68 | + } |
| 69 | + }, |
| 70 | + { |
| 71 | + name: 'not-to-deprecated', |
| 72 | + comment: |
| 73 | + 'This module uses a (version of an) npm module that has been deprecated. Either upgrade to a later ' + |
| 74 | + 'version of that module, or find an alternative. Deprecated modules are a security risk.', |
| 75 | + severity: 'warn', |
| 76 | + from: {}, |
| 77 | + to: { |
| 78 | + dependencyTypes: [ |
| 79 | + 'deprecated' |
| 80 | + ] |
| 81 | + } |
| 82 | + }, |
| 83 | + { |
| 84 | + name: 'no-non-package-json', |
| 85 | + severity: 'error', |
| 86 | + comment: |
| 87 | + "This module depends on an npm package that isn't in the 'dependencies' section of your package.json. " + |
| 88 | + "That's problematic as the package either (1) won't be available on live (2 - worse) will be " + |
| 89 | + "available on live with an non-guaranteed version. Fix it by adding the package to the dependencies " + |
| 90 | + "in your package.json.", |
| 91 | + from: {}, |
| 92 | + to: { |
| 93 | + dependencyTypes: [ |
| 94 | + 'npm-no-pkg', |
| 95 | + 'npm-unknown' |
| 96 | + ] |
| 97 | + } |
| 98 | + }, |
| 99 | + { |
| 100 | + name: 'not-to-unresolvable', |
| 101 | + comment: |
| 102 | + "This module depends on a module that cannot be found ('resolved to disk'). If it's an npm " + |
| 103 | + 'module: add it to your package.json. In all other cases you likely already know what to do.', |
| 104 | + severity: 'error', |
| 105 | + from: {}, |
| 106 | + to: { |
| 107 | + couldNotResolve: true |
| 108 | + } |
| 109 | + }, |
| 110 | + { |
| 111 | + name: 'no-duplicate-dep-types', |
| 112 | + comment: |
| 113 | + "Likely this module depends on an external ('npm') package that occurs more than once " + |
| 114 | + "in your package.json i.e. bot as a devDependencies and in dependencies. This will cause " + |
| 115 | + "maintenance problems later on.", |
| 116 | + severity: 'warn', |
| 117 | + from: {}, |
| 118 | + to: { |
| 119 | + moreThanOneDependencyType: true, |
| 120 | + // as it's pretty common to have a type import be a type only import |
| 121 | + // _and_ (e.g.) a devDependency - don't consider type-only dependency |
| 122 | + // types for this rule |
| 123 | + dependencyTypesNot: ["type-only"] |
| 124 | + } |
| 125 | + }, |
| 126 | + |
| 127 | + /* rules you might want to tweak for your specific situation: */ |
| 128 | + |
| 129 | + { |
| 130 | + name: 'not-to-spec', |
| 131 | + comment: |
| 132 | + 'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' + |
| 133 | + "If there's something in a spec that's of use to other modules, it doesn't have that single " + |
| 134 | + 'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.', |
| 135 | + severity: 'error', |
| 136 | + from: {}, |
| 137 | + to: { |
| 138 | + path: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$' |
| 139 | + } |
| 140 | + }, |
| 141 | + { |
| 142 | + name: 'not-to-dev-dep', |
| 143 | + severity: 'error', |
| 144 | + comment: |
| 145 | + "This module depends on an npm package from the 'devDependencies' section of your " + |
| 146 | + 'package.json. It looks like something that ships to production, though. To prevent problems ' + |
| 147 | + "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" + |
| 148 | + 'section of your package.json. If this module is development only - add it to the ' + |
| 149 | + 'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration', |
| 150 | + from: { |
| 151 | + path: '^(src)', |
| 152 | + pathNot: '[.](?:spec|test)[.](?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$' |
| 153 | + }, |
| 154 | + to: { |
| 155 | + dependencyTypes: [ |
| 156 | + 'npm-dev', |
| 157 | + ], |
| 158 | + // type only dependencies are not a problem as they don't end up in the |
| 159 | + // production code or are ignored by the runtime. |
| 160 | + dependencyTypesNot: [ |
| 161 | + 'type-only' |
| 162 | + ], |
| 163 | + pathNot: [ |
| 164 | + 'node_modules/@types/' |
| 165 | + ] |
| 166 | + } |
| 167 | + }, |
| 168 | + { |
| 169 | + name: 'optional-deps-used', |
| 170 | + severity: 'info', |
| 171 | + comment: |
| 172 | + "This module depends on an npm package that is declared as an optional dependency " + |
| 173 | + "in your package.json. As this makes sense in limited situations only, it's flagged here. " + |
| 174 | + "If you're using an optional dependency here by design - add an exception to your" + |
| 175 | + "dependency-cruiser configuration.", |
| 176 | + from: {}, |
| 177 | + to: { |
| 178 | + dependencyTypes: [ |
| 179 | + 'npm-optional' |
| 180 | + ] |
| 181 | + } |
| 182 | + }, |
| 183 | + { |
| 184 | + name: "no-import-from-local-index", |
| 185 | + severity: "error", |
| 186 | + comment: "do not import from index file of the same level. this will also come up as circular", |
| 187 | + from: { |
| 188 | + path: "src/helpers/" |
| 189 | + }, |
| 190 | + to: { |
| 191 | + path: "src/helpers/index" |
| 192 | + } |
| 193 | + }, |
| 194 | + { |
| 195 | + name: "no-import-from-controls", |
| 196 | + severity: "error", |
| 197 | + comment: "do not import controls into helpers, except for prompt control - by full path not from index", |
| 198 | + from: { |
| 199 | + path: "src/helpers/" |
| 200 | + }, |
| 201 | + to: { |
| 202 | + path: "src/controls", |
| 203 | + pathNot: "src/controls/prompt" |
| 204 | + } |
| 205 | + } |
| 206 | + ], |
| 207 | + options: { |
| 208 | + |
| 209 | + /* Which modules not to follow further when encountered */ |
| 210 | + doNotFollow: { |
| 211 | + /* path: an array of regular expressions in strings to match against */ |
| 212 | + path: ['node_modules'] |
| 213 | + }, |
| 214 | + |
| 215 | + /* Which modules to exclude */ |
| 216 | + // exclude : { |
| 217 | + // /* path: an array of regular expressions in strings to match against */ |
| 218 | + // path: '', |
| 219 | + // }, |
| 220 | + |
| 221 | + /* Which modules to exclusively include (array of regular expressions in strings) |
| 222 | + dependency-cruiser will skip everything not matching this pattern |
| 223 | + */ |
| 224 | + // includeOnly : [''], |
| 225 | + |
| 226 | + /* List of module systems to cruise. |
| 227 | + When left out dependency-cruiser will fall back to the list of _all_ |
| 228 | + module systems it knows of. It's the default because it's the safe option |
| 229 | + It might come at a performance penalty, though. |
| 230 | + moduleSystems: ['amd', 'cjs', 'es6', 'tsd'] |
| 231 | + |
| 232 | + As in practice only commonjs ('cjs') and ecmascript modules ('es6') |
| 233 | + are widely used, you can limit the moduleSystems to those. |
| 234 | + */ |
| 235 | + |
| 236 | + // moduleSystems: ['cjs', 'es6'], |
| 237 | + |
| 238 | + /* |
| 239 | + false: don't look at JSDoc imports (the default) |
| 240 | + true: dependency-cruiser will detect dependencies in JSDoc-style |
| 241 | + import statements. Implies "parser": "tsc", so the dependency-cruiser |
| 242 | + will use the typescript parser for JavaScript files. |
| 243 | + |
| 244 | + For this to work the typescript compiler will need to be installed in the |
| 245 | + same spot as you're running dependency-cruiser from. |
| 246 | + */ |
| 247 | + // detectJSDocImports: true, |
| 248 | + |
| 249 | + /* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/main/' |
| 250 | + to open it on your online repo or `vscode://file/${process.cwd()}/` to |
| 251 | + open it in visual studio code), |
| 252 | + */ |
| 253 | + // prefix: `vscode://file/${process.cwd()}/`, |
| 254 | + |
| 255 | + /* false (the default): ignore dependencies that only exist before typescript-to-javascript compilation |
| 256 | + true: also detect dependencies that only exist before typescript-to-javascript compilation |
| 257 | + "specify": for each dependency identify whether it only exists before compilation or also after |
| 258 | + */ |
| 259 | + tsPreCompilationDeps: true, |
| 260 | + |
| 261 | + /* list of extensions to scan that aren't javascript or compile-to-javascript. |
| 262 | + Empty by default. Only put extensions in here that you want to take into |
| 263 | + account that are _not_ parsable. |
| 264 | + */ |
| 265 | + // extraExtensionsToScan: [".json", ".jpg", ".png", ".svg", ".webp"], |
| 266 | + |
| 267 | + /* if true combines the package.jsons found from the module up to the base |
| 268 | + folder the cruise is initiated from. Useful for how (some) mono-repos |
| 269 | + manage dependencies & dependency definitions. |
| 270 | + */ |
| 271 | + // combinedDependencies: false, |
| 272 | + |
| 273 | + /* if true leave symlinks untouched, otherwise use the realpath */ |
| 274 | + // preserveSymlinks: false, |
| 275 | + |
| 276 | + /* TypeScript project file ('tsconfig.json') to use for |
| 277 | + (1) compilation and |
| 278 | + (2) resolution (e.g. with the paths property) |
| 279 | +
|
| 280 | + The (optional) fileName attribute specifies which file to take (relative to |
| 281 | + dependency-cruiser's current working directory). When not provided |
| 282 | + defaults to './tsconfig.json'. |
| 283 | + */ |
| 284 | + tsConfig: { |
| 285 | + fileName: 'tsconfig.json' |
| 286 | + }, |
| 287 | + |
| 288 | + /* Webpack configuration to use to get resolve options from. |
| 289 | +
|
| 290 | + The (optional) fileName attribute specifies which file to take (relative |
| 291 | + to dependency-cruiser's current working directory. When not provided defaults |
| 292 | + to './webpack.conf.js'. |
| 293 | +
|
| 294 | + The (optional) `env` and `arguments` attributes contain the parameters |
| 295 | + to be passed if your webpack config is a function and takes them (see |
| 296 | + webpack documentation for details) |
| 297 | + */ |
| 298 | + // webpackConfig: { |
| 299 | + // fileName: 'webpack.config.js', |
| 300 | + // env: {}, |
| 301 | + // arguments: {} |
| 302 | + // }, |
| 303 | + |
| 304 | + /* Babel config ('.babelrc', '.babelrc.json', '.babelrc.json5', ...) to use |
| 305 | + for compilation |
| 306 | + */ |
| 307 | + // babelConfig: { |
| 308 | + // fileName: '.babelrc', |
| 309 | + // }, |
| 310 | + |
| 311 | + /* List of strings you have in use in addition to cjs/ es6 requires |
| 312 | + & imports to declare module dependencies. Use this e.g. if you've |
| 313 | + re-declared require, use a require-wrapper or use window.require as |
| 314 | + a hack. |
| 315 | + */ |
| 316 | + // exoticRequireStrings: [], |
| 317 | + |
| 318 | + /* options to pass on to enhanced-resolve, the package dependency-cruiser |
| 319 | + uses to resolve module references to disk. The values below should be |
| 320 | + suitable for most situations |
| 321 | +
|
| 322 | + If you use webpack: you can also set these in webpack.conf.js. The set |
| 323 | + there will override the ones specified here. |
| 324 | + */ |
| 325 | + enhancedResolveOptions: { |
| 326 | + /* What to consider as an 'exports' field in package.jsons */ |
| 327 | + exportsFields: ["exports"], |
| 328 | + /* List of conditions to check for in the exports field. |
| 329 | + Only works when the 'exportsFields' array is non-empty. |
| 330 | + */ |
| 331 | + conditionNames: ["import", "require", "node", "default", "types"], |
| 332 | + /* |
| 333 | + The extensions, by default are the same as the ones dependency-cruiser |
| 334 | + can access (run `npx depcruise --info` to see which ones that are in |
| 335 | + _your_ environment). If that list is larger than you need you can pass |
| 336 | + the extensions you actually use (e.g. [".js", ".jsx"]). This can speed |
| 337 | + up module resolution, which is the most expensive step. |
| 338 | + */ |
| 339 | + // extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], |
| 340 | + /* What to consider a 'main' field in package.json */ |
| 341 | + |
| 342 | + // if you migrate to ESM (or are in an ESM environment already) you will want to |
| 343 | + // have "module" in the list of mainFields, like so: |
| 344 | + // mainFields: ["module", "main", "types", "typings"], |
| 345 | + mainFields: ["main", "types", "typings"], |
| 346 | + /* |
| 347 | + A list of alias fields in package.jsons |
| 348 | + See [this specification](https://github.com/defunctzombie/package-browser-field-spec) and |
| 349 | + the webpack [resolve.alias](https://webpack.js.org/configuration/resolve/#resolvealiasfields) |
| 350 | + documentation |
| 351 | + |
| 352 | + Defaults to an empty array (= don't use alias fields). |
| 353 | + */ |
| 354 | + // aliasFields: ["browser"], |
| 355 | + }, |
| 356 | + reporterOptions: { |
| 357 | + dot: { |
| 358 | + /* pattern of modules that can be consolidated in the detailed |
| 359 | + graphical dependency graph. The default pattern in this configuration |
| 360 | + collapses everything in node_modules to one folder deep so you see |
| 361 | + the external modules, but their innards. |
| 362 | + */ |
| 363 | + collapsePattern: 'node_modules/(?:@[^/]+/[^/]+|[^/]+)', |
| 364 | + |
| 365 | + /* Options to tweak the appearance of your graph.See |
| 366 | + https://github.com/sverweij/dependency-cruiser/blob/main/doc/options-reference.md#reporteroptions |
| 367 | + for details and some examples. If you don't specify a theme |
| 368 | + dependency-cruiser falls back to a built-in one. |
| 369 | + */ |
| 370 | + // theme: { |
| 371 | + // graph: { |
| 372 | + // /* splines: "ortho" gives straight lines, but is slow on big graphs |
| 373 | + // splines: "true" gives bezier curves (fast, not as nice as ortho) |
| 374 | + // */ |
| 375 | + // splines: "true" |
| 376 | + // }, |
| 377 | + // } |
| 378 | + }, |
| 379 | + archi: { |
| 380 | + /* pattern of modules that can be consolidated in the high level |
| 381 | + graphical dependency graph. If you use the high level graphical |
| 382 | + dependency graph reporter (`archi`) you probably want to tweak |
| 383 | + this collapsePattern to your situation. |
| 384 | + */ |
| 385 | + collapsePattern: '^(?:packages|src|lib(s?)|app(s?)|bin|test(s?)|spec(s?))/[^/]+|node_modules/(?:@[^/]+/[^/]+|[^/]+)', |
| 386 | + |
| 387 | + /* Options to tweak the appearance of your graph. If you don't specify a |
| 388 | + theme for 'archi' dependency-cruiser will use the one specified in the |
| 389 | + dot section above and otherwise use the default one. |
| 390 | + */ |
| 391 | + // theme: { }, |
| 392 | + }, |
| 393 | + "text": { |
| 394 | + "highlightFocused": true |
| 395 | + }, |
| 396 | + } |
| 397 | + } |
| 398 | +}; |
| 399 | +// generated: dependency-cruiser@16.8.0 on 2024-12-16T15:33:04.578Z |
0 commit comments