Skip to content
This repository has been archived by the owner on May 22, 2024. It is now read-only.

[package-json-lint] Add a flag to mark a project as application, module, or devModule. #700

Merged
merged 8 commits into from
Aug 31, 2021
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
3 changes: 3 additions & 0 deletions packages/package-json-lint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* Added `projectType` to allow users to flag project as `application`, `module` or `devModule`.

## 1.0.0 - (August 13, 2021)

* Initial stable release
3 changes: 2 additions & 1 deletion packages/package-json-lint/src/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ const lint = ({ packageJsonData, config }) => {
}

const issues = [];
const projectType = config.projectType || 'module';
const rulesToRun = Object.entries(config.rules).map(([ruleId, ruleInformation]) => {
const rule = rules[ruleId];
const ruleConfig = getRuleConfig({ rule, ruleInformation });
if (ruleConfig.severity !== 'off') {
return rule.create({ ruleConfig, report: issue => issues.push(issue) });
return rule.create({ ruleConfig, projectType, report: issue => issues.push(issue) });
}
return undefined;
}).filter(rule => !!rule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ const versionSet = [
];

module.exports = {
create: ({ ruleConfig, report }) => ({
create: ({ ruleConfig, projectType, report }) => ({
dependencies: (dependencies) => requireVersionSet({
versionSet, dependencies, ruleConfig, report, lintId: 'require-no-terra-base-peer-dependency-versions', messageString: 'no terra base peer dependencies',
versionSet, dependencies, ruleConfig, projectType, report, lintId: 'require-no-terra-base-peer-dependency-versions', messageString: 'no terra base peer dependencies',
}),
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ const versionSet = [
];

module.exports = {
create: ({ ruleConfig, report }) => ({
create: ({ ruleConfig, projectType, report }) => ({
dependencies: (dependencies) => requireVersionSet({
versionSet, dependencies, ruleConfig, report, lintId: 'require-theme-context-versions', messageString: 'theming context',
versionSet, dependencies, ruleConfig, projectType, report, lintId: 'require-theme-context-versions', messageString: 'theming context',
}),
}),
};
4 changes: 2 additions & 2 deletions packages/package-json-lint/src/rules/requireVersionSet.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const semver = require('semver');

module.exports = ({
versionSet, dependencies, ruleConfig, report, lintId, messageString,
versionSet, dependencies, ruleConfig, projectType, report, lintId, messageString,
}) => {
const currentProblems = versionSet.map(({ name, versionRange }) => {
const dependencyVersion = dependencies[name];
Expand All @@ -14,7 +14,7 @@ module.exports = ({
if (currentProblems.length) {
const lintMessage = `The dependencies for this project do not have the minimum versions required for ${messageString}:\n ${currentProblems.join('\n ')}`;
report({
lintId, severity: ruleConfig.severity, lintMessage,
lintId, severity: ruleConfig.severity, lintMessage, projectType,
});
}
};
7 changes: 4 additions & 3 deletions packages/package-json-lint/tests/jest/lint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('lint', () => {
'require-no-terra-base-peer-dependency-versions': 'error',
'require-theme-context-versions': 'error',
},
projectType: 'module',
});
getConfigForFile.mockResolvedValueOnce({
rules: {
Expand Down Expand Up @@ -104,10 +105,10 @@ describe('lint', () => {
expect(getRuleConfig).toHaveBeenNthCalledWith(3, { rule: rules['require-no-terra-base-peer-dependency-versions'], ruleInformation: 'warn' });
expect(getRuleConfig).toHaveBeenNthCalledWith(4, { rule: rules['require-theme-context-versions'], ruleInformation: 'warn' });
expect(rules['require-no-terra-base-peer-dependency-versions'].create).toHaveBeenCalledTimes(1);
expect(rules['require-no-terra-base-peer-dependency-versions'].create).toHaveBeenCalledWith({ ruleConfig: package2RuleConfig1, report: expect.anything() });
expect(rules['require-no-terra-base-peer-dependency-versions'].create).toHaveBeenCalledWith({ ruleConfig: package2RuleConfig1, projectType: 'module', report: expect.anything() });
expect(rules['require-theme-context-versions'].create).toHaveBeenCalledTimes(2);
expect(rules['require-theme-context-versions'].create).toHaveBeenCalledWith({ ruleConfig: package1RuleConfig2, report: expect.anything() });
expect(rules['require-theme-context-versions'].create).toHaveBeenCalledWith({ ruleConfig: package2RuleConfig2, report: expect.anything() });
expect(rules['require-theme-context-versions'].create).toHaveBeenCalledWith({ ruleConfig: package1RuleConfig2, projectType: 'module', report: expect.anything() });
expect(rules['require-theme-context-versions'].create).toHaveBeenCalledWith({ ruleConfig: package2RuleConfig2, projectType: 'module', report: expect.anything() });
expect(mockRule1.dependencies).toHaveBeenCalledTimes(1);
expect(mockRule1.dependencies).toHaveBeenCalledWith({ b: '1.1.1' });
expect(mockRule2.dependencies).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Object {
"lintId": "require-no-terra-base-peer-dependency-versions",
"lintMessage": "The dependencies for this project do not have the minimum versions required for no terra base peer dependencies:
terra-action-footer@^1.0.0 does not satisfy range requirement for no terra base peer dependencies: terra-action-footer@>2.5.0",
"projectType": "module",
"severity": "warning",
}
`;
Expand Down Expand Up @@ -86,6 +87,7 @@ Object {
[email protected] does not satisfy range requirement for no terra base peer dependencies: terra-toggle-section-header@>2.5.0
[email protected] does not satisfy range requirement for no terra base peer dependencies: terra-toggle@>3.5.0
[email protected] does not satisfy range requirement for no terra base peer dependencies: terra-visually-hidden-text@>2.4.0",
"projectType": "devModule",
"severity": "error",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Object {
"lintId": "require-theme-context-versions",
"lintMessage": "The dependencies for this project do not have the minimum versions required for theming context:
terra-action-footer@^1.0.0 does not satisfy range requirement for theming context: terra-action-footer@>=2.42.0",
"projectType": "module",
"severity": "warning",
}
`;
Expand Down Expand Up @@ -85,6 +86,7 @@ Object {
terra-text@<4.31.0 does not satisfy range requirement for theming context: terra-text@>=4.31.0
terra-time-input@<4.29.0 does not satisfy range requirement for theming context: terra-time-input@>=4.29.0
terra-toolbar@<1.8.0 does not satisfy range requirement for theming context: terra-toolbar@>=1.8.0",
"projectType": "module",
"severity": "error",
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('require-no-terra-base-peer-dependency-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
}).dependencies({});
expect(results).toMatchSnapshot();
});
Expand All @@ -15,6 +16,7 @@ describe('require-no-terra-base-peer-dependency-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
}).dependencies({
a: '^1.0.0',
});
Expand All @@ -27,6 +29,7 @@ describe('require-no-terra-base-peer-dependency-versions', () => {
ruleConfig: {
severity: 'warning',
},
projectType: 'module',
report: (issues) => {
results = issues;
},
Expand All @@ -42,6 +45,7 @@ describe('require-no-terra-base-peer-dependency-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'devModule',
report: (issues) => {
results = issues;
},
Expand Down Expand Up @@ -128,6 +132,7 @@ describe('require-no-terra-base-peer-dependency-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
}).dependencies({
'terra-action-footer': '^2.6.0',
'terra-action-header': '^2.9.0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe('require-theme-context-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
}).dependencies({});
expect(results).toMatchSnapshot();
});
Expand All @@ -15,6 +16,7 @@ describe('require-theme-context-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
}).dependencies({
a: '^1.0.0',
});
Expand All @@ -27,6 +29,7 @@ describe('require-theme-context-versions', () => {
ruleConfig: {
severity: 'warning',
},
projectType: 'module',
report: (issues) => {
results = issues;
},
Expand All @@ -42,6 +45,7 @@ describe('require-theme-context-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
report: (issues) => {
results = issues;
},
Expand Down Expand Up @@ -127,6 +131,7 @@ describe('require-theme-context-versions', () => {
ruleConfig: {
severity: 'error',
},
projectType: 'module',
}).dependencies({
'@cerner/terra-docs': '^1.0.0',
'terra-abstract-modal': '^3.25.0',
Expand Down