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

[FEATURE] Add Configuration Schema #274

Merged
merged 44 commits into from
Mar 24, 2020
Merged

[FEATURE] Add Configuration Schema #274

merged 44 commits into from
Mar 24, 2020

Conversation

matz3
Copy link
Member

@matz3 matz3 commented Mar 12, 2020

Thank you for your contribution! 🙌

To get it merged faster, kindly review the checklist below:

Pull Request Checklist

@coveralls
Copy link

coveralls commented Mar 12, 2020

Coverage Status

Coverage increased (+1.5%) to 89.812% when pulling 2341c79 on schema into 6b717fd on master.

Copy link
Member

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

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

I like what I see

lib/projectPreprocessor.js Outdated Show resolved Hide resolved
lib/schema/validate.js Outdated Show resolved Hide resolved
@matz3 matz3 requested a review from svbender March 19, 2020 10:58
@matz3 matz3 marked this pull request as ready for review March 20, 2020 08:38
@matz3
Copy link
Member Author

matz3 commented Mar 20, 2020

Should be rebased on top of #277

const escapeStringRegExp = require("escape-string-regexp");
const matchAll = require("string.prototype.matchall");

class ValidationError extends Error {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am really missing some jsdoc here for the class and methods.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

"properties": {
"specVersion": { "enum": ["2.0"] },
"kind": {
"enum": ["project", null]
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the enum entry "null" for?

Copy link
Member Author

Choose a reason for hiding this comment

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

The default when it's not defined. I've added comments.

return JSON.parse(schemaFile);
}

class Validator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, no documentation. Most of the methods logic is obvious but at least the class could use some doc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done for the public API

});

t.is(validationError.errors.length, 1, "ValidationError should have one error object");
t.is(validationError.errors.length, 1, "ValidationError should have one error object");
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate assertion

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -3,8 +3,9 @@ const fs = require("graceful-fs");
const path = require("path");
const {promisify} = require("util");
const readFile = promisify(fs.readFile);
const parseYaml = require("js-yaml").safeLoadAll;
const {loadAll: parseYaml, DEFAULT_SAFE_SCHEMA} = require("js-yaml");
Copy link
Member

Choose a reason for hiding this comment

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

This change is needed because of the issues with safeLoadAll? If yes, maybe add a comment for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good point. Done.

lib/projectPreprocessor.js Show resolved Hide resolved
lib/projectPreprocessor.js Outdated Show resolved Hide resolved
Copy link
Member

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

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

I did not look into all the new tests, it's just too much. But that's still a good thing 👍

lib/projectPreprocessor.js Show resolved Hide resolved
lib/validation/ValidationError.js Show resolved Hide resolved
lib/validation/ValidationError.js Show resolved Hide resolved
lib/validation/ValidationError.js Show resolved Hide resolved
lib/validation/ValidationError.js Show resolved Hide resolved
lib/validation/schema/specVersion/2.0/kind/extension.json Outdated Show resolved Hide resolved
test/lib/projectPreprocessor.js Show resolved Hide resolved
test/lib/projectPreprocessor.js Show resolved Hide resolved
Copy link
Member

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

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

* @param {number} [options.yaml.documentIndex=0] Document index in case the YAML file contains multiple documents
* @throws {module:@ui5/project.validation.ValidationError}
* Throws a {@link module:@ui5/project.validation.ValidationError ValidationError} when the validation fails.
* @returns {undefined} Returns when the validation succeeds
Copy link
Member

Choose a reason for hiding this comment

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

Returns a Promise, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@matz3
Copy link
Member Author

matz3 commented Mar 24, 2020

Tests should be fixed now.

const yaml = {
path: "/my-project/ui5.yaml",
source:
`---
Copy link
Member

Choose a reason for hiding this comment

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

What about one (or multiple) newlines at the beginning of the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Done 👍

source: configFile,
documentIndex
configs.map(async (config, documentIndex) => {
try {
Copy link
Member

Choose a reason for hiding this comment

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

We should document that the try/catch block here is required to get the first error of the first document. And not the first error to occur in any document.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

RandomByte
RandomByte previously approved these changes Mar 24, 2020
Copy link
Member

@RandomByte RandomByte left a comment

Choose a reason for hiding this comment

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

I like it, let's enforce the schema!!!11

🚓 👮 👮‍♀ 🚔

@matz3 matz3 merged commit eb961c3 into master Mar 24, 2020
@matz3 matz3 deleted the schema branch March 24, 2020 20:01
Copy link
Contributor

@KlattG KlattG left a comment

Choose a reason for hiding this comment

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

Whenever errors are triggered, the word "should" is not strong enough. Please replace "should" by "must" in all error messages.

schemaPath: "#/type",
};

const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("foo"))} should be of type 'object'`;
Copy link
Contributor

Choose a reason for hiding this comment

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

"should" --> "must"

schemaPath: "#/required",
};

const expectedErrorMessage = "Configuration should have required property 'specVersion'";
Copy link
Contributor

Choose a reason for hiding this comment

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

"Configuration must have the required property 'specVersion'"

message: "should have required property 'name'"
};

const expectedErrorMessage = `Configuration ${chalk.underline(chalk.red("metadata"))} should have required property 'name'`;
Copy link
Contributor

Choose a reason for hiding this comment

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

"Configuration ${chalk.underline(chalk.red("metadata"))} must have the required property 'name'"

};

const expectedErrorMessage =
`Configuration ${chalk.underline(chalk.red("type"))} should be equal to one of the allowed values
Copy link
Contributor

Choose a reason for hiding this comment

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

"Configuration ${chalk.underline(chalk.red("type"))} must be equal to one of the allowed values"

};

const expectedErrorMessage =
`Configuration ${chalk.underline(chalk.red("resources/configuration"))} property propertiesFileEncoding is not expected to be here`;
Copy link
Contributor

Choose a reason for hiding this comment

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

"Configuration ${chalk.underline(chalk.red("resources/configuration"))} property propertiesFileEncoding must not be provided here"

@matz3
Copy link
Member Author

matz3 commented Mar 26, 2020

Thanks @KlattG 👍
Will be addressed with #292

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.

None yet

5 participants