Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Add linting #19

wants to merge 1 commit into from

Conversation

lukekarrys
Copy link
Contributor

@lukekarrys lukekarrys commented Aug 19, 2024

This goes on top of #18. Keeping in draft until that lands.

Lint only diff: 5409823

This is ready for review.

@lukekarrys lukekarrys force-pushed the lk/linting branch 2 times, most recently from ebb3a09 to 5409823 Compare August 19, 2024 20:17
@lukekarrys lukekarrys force-pushed the lk/linting branch 2 times, most recently from 292a70a to 26e0a98 Compare October 8, 2024 19:14
@lukekarrys lukekarrys marked this pull request as ready for review October 8, 2024 19:20
@@ -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}`)
Copy link
Contributor Author

@lukekarrys lukekarrys Oct 8, 2024

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)}`,
Copy link
Contributor Author

@lukekarrys lukekarrys Oct 8, 2024

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant