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

Revise warning message for configuration "pages" property #1318

Merged
merged 4 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/import/importConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,18 +915,22 @@ function detectPotentialMistakes(yaml: YAMLConfiguration) {
);
if (additionalPropertiesErrors.length > 0) {
const parentProperty = instancePath === '' ? '' : `property ${instancePath.slice(1)} `;
const propertyWord = additionalPropertiesErrors.length === 1 ? 'property' : 'properties';
const singular = additionalPropertiesErrors.length === 1;
const additionalPropertyNames = additionalPropertiesErrors
.map(validationError => validationError.params.additionalProperty)
.join(', ');
let recommendation: string;
let recommendation = `Check that ${
singular ? 'this property is' : 'these properties are'
} spelled, capitalized, and indented correctly.`;
if (instancePath.startsWith('/pages')) {
recommendation = 'Pages should end with .md, .xml, or .html.';
} else {
recommendation = 'Check that these properties are spelled and indented correctly.';
recommendation += ` If ${
singular ? 'this is a page, it' : 'these are pages, they'
} should end with .md, .xml, or .html.`;
}
logger.warn(
`Configuration ${parentProperty}contains unexpected ${propertyWord}: ${additionalPropertyNames}. ${recommendation}`
`Configuration ${parentProperty}contains unexpected ${
singular ? 'property' : 'properties'
}: ${additionalPropertyNames}. ${recommendation}`
);
} else {
logger.warn(
Expand Down
8 changes: 4 additions & 4 deletions test/import/importConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ describe('importConfiguration', () => {
expect(actual).toEqual(expected);
expect(loggerSpy.getAllLogs('error')).toHaveLength(0);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Configuration contains unexpected property: cookie. Check that these properties are spelled and indented correctly.'
'Configuration contains unexpected property: cookie. Check that this property is spelled, capitalized, and indented correctly.'
);
});

Expand Down Expand Up @@ -503,7 +503,7 @@ describe('importConfiguration', () => {
expect(actual).toEqual(expected);
expect(loggerSpy.getAllLogs('error')).toHaveLength(0);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Configuration contains unexpected properties: cookie, index.md. Check that these properties are spelled and indented correctly.'
'Configuration contains unexpected properties: cookie, index.md. Check that these properties are spelled, capitalized, and indented correctly.'
);
});

Expand Down Expand Up @@ -2168,7 +2168,7 @@ describe('importConfiguration', () => {
}
]);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Configuration property pages contains unexpected property: menu. Pages should end with .md, .xml, or .html.'
'Configuration property pages contains unexpected property: menu. Check that this property is spelled, capitalized, and indented correctly. If this is a page, it should end with .md, .xml, or .html.'
);
});

Expand Down Expand Up @@ -2202,7 +2202,7 @@ describe('importConfiguration', () => {
{ nameUrl: 'license', page: [] }
]);
expect(loggerSpy.getLastMessage('warn')).toMatch(
'Configuration property pages contains unexpected properties: menu, license. Pages should end with .md, .xml, or .html.'
'Configuration property pages contains unexpected properties: menu, license. Check that these properties are spelled, capitalized, and indented correctly. If these are pages, they should end with .md, .xml, or .html.'
);
});

Expand Down
Loading