-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add customRulePackages config option #220
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aldeed I'm sorry for the late reply. I took a look at the PR when you first opened it and seemingly forgot to submit the review so it's been in draft since then. 🤦
Does this implementation seem good?
Yeah, looks good to me. 😄
I added the new option to the config resolver but not to the CLI command options. Should it be added to CLI, too?
Might be a good idea for consistency.
Unsure how best to write tests for this. Should I build a whole project in a temp dir and "install" a fake package in node_modules and then programmatically run the check?
That's a good question. 🤔 I think what you suggested sounds good to me. We don't necessarily need to try to make this work with the existing test structure. I wouldn't mind just adding it as another step in .travis.yml
. I added a few high-level integration tests like this already.
graphql-schema-linter/.travis.yml
Lines 11 to 12 in bc080a4
- node lib/cli.js test/fixtures/valid.graphql | |
- cat test/fixtures/valid.graphql | node lib/cli.js --stdin |
In other words, feel free to create a separate file for this if it makes things easier, maybe a shell (or JS) script that we execute there.
// We can't simply call `require()` because it needs to be from the project's node_modules | ||
const rulePackagePath = ModuleResolver.resolve( | ||
rulePackage, | ||
path.join(process.cwd(), '__placeholder__.js') | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhhh, that's interesting. I hadn't even considered that. 🤔
Btw did the path you are passing need to be a file and not a folder? In other words, the __placeholder__.js
was required and is okay if it does not actually exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cjoudrey I actually borrowed this bit of code from the eslint packages: https://github.com/eslint/eslint/blob/a47770706ac59633dcd73e886d1a7282b324ee06/lib/init/config-initializer.js#L350
I actually don't know if a folder would work, but they probably added the placeholder for a reason? 😄If I remember when I'm finishing this PR, I'll see if it works with just the CWD.
@cjoudrey That all sounds good. I'll finish this as soon as I get a chance. |
Any update on this? I was looking for similar functionality. |
@mcwoodle Honestly completely forgot about this, but I can put it back on the to-do list. |
+1, this would be a useful feature for us! To have a central location of rules that all our subgraphs can rely on. |
This is not quite what I proposed in #217 . Adding full
extends
proved a bit tricky so I concentrated on the most important thing: ability to distribute custom rules in an NPM package.Added
customRulePackages
config option. It works likecustomRulePaths
except you list NPM package names. It assumes that the named exports from each package's main entry file are each rules. You have to npm/yarn install any packages you list.Testing
npm link
oryarn link
this branch into your project that usesgraphql-schema-linter
gqlsl-custom-rules
innode_modules
in the projectindex.js
file in that folder and export at least one rule from itcustomRulePackages: ["gqlsl-custom-rules"]
in yourgraphql-schema-linter
config file for the projectrules
list in yourgraphql-schema-linter
config file for the project. Must match the name of the export.Notes
The
relative_module_resolver.js
file I added is from https://github.com/eslint/eslint/blob/master/lib/shared/relative-module-resolver.js. Both packages are MIT licensed so this should be fine.Not ready to merge yet. I will add documentation after the questions below are answered.
Questions
node_modules
and then programmatically run the check?