-
-
Notifications
You must be signed in to change notification settings - Fork 4
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 linting #19
base: main
Are you sure you want to change the base?
Add linting #19
Conversation
ebb3a09
to
5409823
Compare
292a70a
to
26e0a98
Compare
@@ -1003,7 +1008,7 @@ export class Jack<C extends ConfigSet = {}> { | |||
) | |||
} | |||
if (this.#configSet[name]) { | |||
throw new TypeError(`Cannot redefine option ${field}`) | |||
throw new TypeError(`Cannot redefine option ${name}`) |
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.
This was a bug found via linting:
import { jack } from "jackspeak";
const j = jack()
.opt({
x: {
description: "desc",
},
})
.opt({
x: {
description: "desc",
},
});
file:///Users/lukekarrys/Desktop/scratch/jackspeak-lint-changes/node_modules/jackspeak/dist/esm/index.js:571
throw new TypeError(`Cannot redefine option ${field}`);
^
TypeError: Cannot redefine option [object Object]
cause, | ||
}) | ||
throw new Error( | ||
`Invalid config value for ${field}: ${JSON.stringify(value)}`, |
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.
This was also found via linting. The change helps distinguish between primitive and non-primitive values in error messages:
import { jack } from "jackspeak";
const j = jack()
.optList({ xlist: { validate: () => false } })
.opt({ x: { validate: () => false } });
const validate = (o) => {
try {
j.validate(o);
} catch (e) {
console.log(e.message);
}
};
validate({ xlist: ["a", "b", "c"] });
validate({ x: "a,b,c" });
before
❯ node index.mjs
Invalid config value for xlist: a,b,c
Invalid config value for x: a,b,c
after
❯ node index.mjs
Invalid config value for xlist: ["a","b","c"]
Invalid config value for x: "a,b,c"
This goes on top of #18. Keeping in draft until that lands.Lint only diff: 5409823This is ready for review.