-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable shopify/no-ancestor-directory-import eslint rule
Importing from the component index leads to circular depdendencies that cause issues when trying to optimize builds upstream. See this essay https://github.com/Shopify/sewing-kit/blob/2bbf40fee4b6fc6e8a2cbbab1b743b47532b98eb/src/tools/webpack/tests/config/rules/javascript.test.ts#L215-L268 This commit adds tooling to help idenify cycles and stop them, so that sewing-kit can remove its workarounds. * Depdendency Cruiser (`yarn run depcruise-validate`) shall help idenfity cycles. * shopify/no-ancestor-directory-import is an eslint rule that bars imports from parent indexes, which is the most common cause of cycles. Fix current ancestort imports to import from direct files. This is not enforced in tests because. test files will not be imported by anything else so there is no danger of cylical imports.
- Loading branch information
Showing
53 changed files
with
541 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"forbidden": [ | ||
{ | ||
"name": "not-to-test", | ||
"comment": "Don't allow dependencies from outside the test folder to test", | ||
"severity": "error", | ||
"from": {"pathNot": "(^(tests|spec))|\\.test\\.(ts|tsx)$"}, | ||
"to": {"path": "^(tests|spec)"} | ||
}, | ||
{ | ||
"name": "not-to-spec", | ||
"comment": "Don't allow dependencies to (typescript/ javascript/ coffeescript) spec files", | ||
"severity": "error", | ||
"from": {}, | ||
"to": { | ||
"path": "\\.(test|spec)\\.(js|ts|ls|coffee|litcoffee|coffee\\.md)$" | ||
} | ||
}, | ||
{ | ||
"name": "no-circular", | ||
"severity": "warn", | ||
"comment": "Warn in case there's circular dependencies", | ||
"from": {}, | ||
"to": {"circular": true} | ||
}, | ||
{ | ||
"name": "no-orphans", | ||
"severity": "info", | ||
"comment": "Inform in case there's orphans hiding in the code base", | ||
"from": { | ||
"orphan": true, | ||
"pathNot": "(^src/styles/polaris-tokens)|\\.d\\.ts$" | ||
}, | ||
"to": {} | ||
}, | ||
{ | ||
"name": "no-deprecated-core", | ||
"comment": "Warn about dependencies on deprecated core modules.", | ||
"severity": "warn", | ||
"from": {}, | ||
"to": { | ||
"dependencyTypes": ["core"], | ||
"path": "^(punycode|domain|constants|sys|_linklist)$" | ||
} | ||
}, | ||
{ | ||
"name": "no-deprecated-npm", | ||
"comment": "These npm modules are deprecated - find an alternative.", | ||
"severity": "warn", | ||
"from": {}, | ||
"to": {"dependencyTypes": ["deprecated"]} | ||
}, | ||
{ | ||
"name": "not-to-unresolvable", | ||
"comment": "Don't allow dependencies on modules dependency-cruiser can't resolve to files on disk (which probably means they don't exist)", | ||
"severity": "error", | ||
"from": {}, | ||
"to": {"couldNotResolve": true} | ||
}, | ||
{ | ||
"name": "not-to-dev-dep", | ||
"severity": "error", | ||
"comment": "Don't allow dependencies from src/app/lib to a development only package", | ||
"from": { | ||
"path": "^(src|app|lib)", | ||
"pathNot": "\\.(spec|test)\\.(js|ts|tsx|ls|coffee|litcoffee|coffee\\.md)$" | ||
}, | ||
"to": { | ||
"dependencyTypes": ["npm-dev"], | ||
"pathNot": "^node_modules/(react|enzyme)" | ||
} | ||
}, | ||
{ | ||
"name": "no-non-package-json", | ||
"severity": "error", | ||
"comment": "Don't allow dependencies to packages not in package.json (except from within node_modules)", | ||
"from": {"pathNot": "^node_modules"}, | ||
"to": { | ||
"dependencyTypes": [ | ||
"unknown", | ||
"undetermined", | ||
"npm-no-pkg", | ||
"npm-unknown" | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "optional-deps-used", | ||
"severity": "info", | ||
"comment": "nothing serious - but just check you have some serious try/ catches around the import/ requires of these", | ||
"from": {}, | ||
"to": {"dependencyTypes": ["npm-optional"]} | ||
}, | ||
{ | ||
"name": "peer-deps-used", | ||
"comment": "Warn about the use of a peer dependency (peer dependencies are deprecated with the advent of npm 3 - and probably gone with version 4).", | ||
"severity": "warn", | ||
"from": {}, | ||
"to": {"dependencyTypes": ["npm-peer"], "pathNot": "^node_modules/react"} | ||
}, | ||
{ | ||
"name": "no-duplicate-dep-types", | ||
"comment": "Warn if a dependency you're actually using occurs in your package.json more than once (technically: has more than one dependency type)", | ||
"severity": "warn", | ||
"from": {}, | ||
"to": { | ||
"moreThanOneDependencyType": true, | ||
"pathNot": "^node_modules/react" | ||
} | ||
} | ||
], | ||
"options": { | ||
"doNotFollow": "node_modules" /* pattern specifying which files not to follow further when encountered*/, | ||
// "exclude" : "", /* pattern specifying which files to exclude (regular expression) */ | ||
// "moduleSystems": ["amd", "cjs", "es6", "tsd"],/* list of module systems to cruise */ | ||
// "prefix": "", /* prefix for links in html and svg output (e.g. https://github.com/you/yourrepo/blob/develop/) */ | ||
// "tsPreCompilationDeps": false, /* if true detect dependencies that only exist before typescript-to-javascript compilation */ | ||
// "preserveSymlinks": false, /* if true leave symlinks untouched, otherwise use the realpath */ | ||
"tsConfig": { | ||
/* Typescript project file ('tsconfig.json') to use for (1) compilation and (2) resolution (e.g. with the paths property) */ | ||
"fileName": "./tsconfig.json" /* The typescript project file to use. The fileName is relative to dependency-cruiser's current working directory. When not provided defaults to './tsconfig.json'.*/ | ||
} | ||
// "webpackConfig": { /* Webpack configuration to use to get resolve options from */ | ||
// "fileName": "./webpack.conf.js", /* The webpack conf file to use (typically something like 'webpack.conf.js'). The fileName is relative to dependency-cruiser's current working directory. When not provided defaults to './webpack.conf.js'. */ | ||
// "env": {}, /* Environment to pass if your config file returns a function */ | ||
// "args": {} /* Arguments to pass if your config file returns a function. E.g. {mode: 'production'} if you want to use webpack 4's 'mode' feature */ | ||
//} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/Autocomplete/components/ComboBox/components/TextField/TextField.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 12 additions & 6 deletions
18
src/components/DropZone/components/FileUpload/FileUpload.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
src/components/Frame/components/ContextualSaveBar/ContextualSaveBar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
...onents/ContextualSaveBar/components/DiscardConfirmationModal/DiscardConfirmationModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.