Skip to content

Conversation

cdsiats
Copy link
Contributor

@cdsiats cdsiats commented Feb 5, 2025

What is this PR for?

  • Just updating content and/or documentation
  • This fixes issue Allow "schema.json" to be passed as an input in the CLI #7
  • Spot fix (no issue #)
  • Merging WIP feature #_____
  • Merging done feature #_____
  • This is a merge from a version branch
  • Adding/Updating tests
  • This is a conflict resolution
  • This is a branch cleanup
  • Other: ________________

I verify that...

  • I have logged my time in the commits
  • I have logged my time in this PR
  • I have tagged all the relevant issues
  • I am using VS Code for type checks and linting, or
  • I have ran npm run test with no errors
  • I have manually checked that this bug or feature is working

Copy link
Contributor

@cblanquera cblanquera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several changes needed.

  1. Please follow code syntax patterns in each file you are working on. Try not to introduce new patterns, unless it's absolutely necessary. In this case your comments are wildly and inconsistently formatted.
  2. ? is an escape pattern that may cause additional bugs down the line. In this particular case, since the tests were passing, these additions to the code were unnecessary.

}
//parse schema
const schema = parse(fs.readFileSync(this.input, 'utf8'));
// read input file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow commenting pattern in file. no spaces after // ie. //read input file

const schema = parse(fs.readFileSync(this.input, 'utf8'));
// read input file
const content = fs.readFileSync(this.input, 'utf8');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line.

// read input file
const content = fs.readFileSync(this.input, 'utf8');

// parse schema
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow commenting pattern in file. no spaces after // ie. //parse schema

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow commenting pattern in file. Avoid lateral commenting. Commenting should be above the code in question. ie.

//parse directly
? JSON.parse(content) 

const schema: SchemaConfig = path.extname(this.input) === '.json'
? JSON.parse(content) // parse directly
: parse(content); // parse as normal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this empty line.

}
}
if (child.model) {
if (child?.model) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ?. Tests still pass without this.

schema.model = schema.model || {};
//loop through child types
for (const [ name, model ] of Object.entries(child.model)) {
for (const [ name, model ] of Object.entries(child?.model)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ?. Tests still pass without this.

//ensure the plugin not exists or is not object
//if the conditions are true will throw an error.
if (!this.schema.plugin || typeof this.schema.plugin !== 'object') {
if (!this.schema?.plugin || typeof this.schema?.plugin !== 'object') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ?. Tests still pass without this.

}
//loop through plugins
for (const plugin in this.schema.plugin) {
for (const plugin in this.schema?.plugin) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ?. Tests still pass without this.

const module = this.loader.absolute(plugin);
//get the plugin config
const config = this.schema.plugin[plugin] as Record<string, any>;
const config = this.schema?.plugin[plugin] as Record<string, any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove ?. Tests still pass without this.

@cdsiats cdsiats requested a review from cblanquera February 6, 2025 02:13
@cblanquera cblanquera merged commit 4db1d7e into stackpress:main Feb 6, 2025
3 checks passed
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.

2 participants