Skip to content

Commit

Permalink
Fix import/no-extraneous-deps config (#296)
Browse files Browse the repository at this point in the history
## Summary:
It turns out that setting the "packageDir" option on this rule to be an array of all of the packages ends up checking the package.json in each of those directories when checking **any** file in the whole project.

What we want is to only consult the package.json that lives in packages/perseus/ when linting the files in that subdirectory.  Thankfully, eslint supports cascading config files.  This means we can add an .eslintrc.js in each of our packages' directories with only the 'import/no-extraneous-deps' rule.  Eslint will combine that with the .eslintrc.js at the root when linting files in each package directory.

Issue: None

## Test plan:
- remove '@khanacademy/wonder-blocks-clickable' from packages/perseus/package.json
- see that widges/radio/choice.jsx now has a lint error for that import

Author: kevinbarabash

Reviewers: jeresig, handeyeco

Required Reviewers:

Approved By: jeresig

Checks: ✅ codecov/project, ✅ Lint, Flow, and Test (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ✅ Jest Coverage (ubuntu-latest, 16.x), ✅ Check for .changeset file (ubuntu-latest, 16.x), ✅ Cypress Coverage (ubuntu-latest, 16.x), ✅ Check builds for changes in size (ubuntu-latest, 16.x), ✅ gerald

Pull Request URL: #296
  • Loading branch information
kevinbarabash authored Oct 4, 2022
1 parent 0245e26 commit bf180fe
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 13 deletions.
14 changes: 14 additions & 0 deletions .changeset/popular-paws-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"perseus-build-settings": patch
"@khanacademy/kas": patch
"@khanacademy/kmath": patch
"@khanacademy/math-input": patch
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
"@khanacademy/perseus-error": patch
"@khanacademy/perseus-linter": patch
"@khanacademy/pure-markdown": patch
"@khanacademy/simple-markdown": patch
---

Fix our use of import/no-extraneous-dependencies
12 changes: 1 addition & 11 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ const pkgAliases = pkgNames.map((pkgName) => {
return [`@khanacademy/${pkgName}`, `./packages/${pkgName}/src/index.js`];
});

const pkgDirs = pkgNames.map((pkgName) => {
return `./packages/${pkgName}`;
});

const vendorAliases = fs
.readdirSync(path.join(__dirname, "vendor"))
.map((name) => {
Expand All @@ -35,7 +31,7 @@ module.exports = {
parser: "@babel/eslint-parser",
parserOptions: {
babelOptions: {
configFile: "./config/build/babel.config.js",
configFile: path.join(__dirname, "./config/build/babel.config.js"),
},
},
plugins: [
Expand Down Expand Up @@ -180,12 +176,6 @@ module.exports = {
ignorePackages: true,
},
],
"import/no-extraneous-dependencies": [
"error",
{
packageDir: pkgDirs,
},
],
"import/no-restricted-paths": [
"error",
{
Expand Down
6 changes: 6 additions & 0 deletions packages/kas/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
6 changes: 6 additions & 0 deletions packages/kmath/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
6 changes: 6 additions & 0 deletions packages/math-input/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
6 changes: 6 additions & 0 deletions packages/perseus-editor/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
1 change: 1 addition & 0 deletions packages/perseus-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
"dependencies": {
"@khanacademy/kas": "^0.2.5",
"@khanacademy/kmath": "^0.0.6",
"@khanacademy/perseus": "^0.4.2"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/perseus-error/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
6 changes: 6 additions & 0 deletions packages/perseus-linter/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
7 changes: 5 additions & 2 deletions packages/perseus-linter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
"@khanacademy/perseus-error": "^0.1.1"
},
"devDependencies": {
"@khanacademy/pure-markdown": "^0.1.1"
"@khanacademy/pure-markdown": "^0.1.1",
"prop-types": "^15.6.1"
},
"peerDependencies": {
"prop-types": "^15.6.1"
},
"peerDependencies": {},
"keywords": []
}
6 changes: 6 additions & 0 deletions packages/perseus/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
6 changes: 6 additions & 0 deletions packages/pure-markdown/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};
6 changes: 6 additions & 0 deletions packages/simple-markdown/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable import/no-commonjs */
module.exports = {
rules: {
"import/no-extraneous-dependencies": "error",
},
};

0 comments on commit bf180fe

Please sign in to comment.