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

Commit

Permalink
Added documentation for package-json-lint
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav300 committed Sep 15, 2021
1 parent 80c4eb1 commit 0095a1f
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 1 deletion.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@
"extends": "./packages/package-json-lint-config-terra/package-json-lint.config.js",
"projectType": "devModule",
"rules": {
"require-no-hard-coded-dependency-versions": {"severityType": "error", "allowList": ["eslint-plugin-react", "axe-core"] }
"require-no-hard-coded-dependency-versions": {
"severityType": "error",
"allowList": [
"eslint-plugin-react",
"axe-core",
"inquirer"
]
}
}
},
"eslintConfig": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
const documentation = {
ruleName: 'require-no-hard-coded-dependency-versions',
severityType: ['error', 'warn'],
required: false,
default: 'error',
description: "This rule doesn't allow any hard-coded dependencies to be passed in the package-json. Only applies for module and devModule",
};

module.exports = {
create: ({ ruleConfig, projectType, report }) => ({
dependencies: (dependencies) => {
Expand All @@ -22,4 +30,5 @@ module.exports = {
}
},
}),
documentation,
};
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@ const versionSet = [
{ name: 'terra-visually-hidden-text', versionRange: '>2.4.0' },
];

const documentation = {
ruleName: 'require-no-terra-base-peer-dependency-versions',
severityType: ['error', 'warn'],
required: false,
default: 'warn',
description: "This rule doesn't allow to use terra packages versions that use terra-base as a peerDependency",
};

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

const documentation = {
ruleName: 'require-theme-context-versions',
severityType: ['error', 'warn'],
required: false,
default: 'warn',
description: "This rule doesn't allow to use terra packages versions that don't use terra-theme-context as a Dependency",
};

module.exports = {
create: ({ ruleConfig, projectType, report }) => ({
dependencies: (dependencies) => requireVersionSet({
versionSet, dependencies, ruleConfig, projectType, report, lintId: 'require-theme-context-versions', messageString: 'theming context',
}),
}),
documentation,
};
1 change: 1 addition & 0 deletions packages/terra-functional-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"glob": "^7.1.6",
"gm": "^1.23.1",
"image-size": "^0.8.3",
"inquirer": "8.1.3",
"ip": "^1.1.5",
"jimp": "^0.13.0",
"lodash.get": "^4.4.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-toolkit-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* Added documentation for `package-json-lint`.

## 2.4.0 - (September 2, 2021)

* Removed
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Badge } from '@cerner/package-json-lint/package.json?dev-site-package';

<Badge />

# Package Json Lint
The package provide lint rules that can be used to flag problems that are present in a package.json.


## Installation

To install the module:

```shell
npm install @cerner/package-json-lint --save-dev
npm install @cerner/package-json-lint-config-terra --save-dev
```

## Usage

### package.json
```js
"package-json-lint": {
"extends": "./packages/package-json-lint-config-terra/package-json-lint.config.js",
"projectType": "devModule | module | application",
},
```

### npm script

```js
"lint:package-json": "npm run terra -- package-json-lint",
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Badge } from '@cerner/package-json-lint/package.json?dev-site-package';

import ChangeLog from '@cerner/package-json-lint/CHANGELOG.md';

<Badge />

<ChangeLog />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Badge } from '@cerner/package-json-lint/package.json?dev-site-package';

import RulesTable from './rules-table/_RulesTable.jsx';

<Badge />

# Package JSON Lint Rules

<RulesTable />
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@import '@cerner/terra-dev-site/lib/mdx/MarkdownTags.module';
// @import './clinical-lowlight-theme/PropsTable.module';
// @import './orion-fusion-theme/PropsTable.module';

:local {
.required {
color: #d53040;
}

.props-tr {
vertical-align: top;
}

.props-td {
overflow-wrap: break-word;
white-space: normal;
word-wrap: break-word;
}

.tr {
background-color: var(--terra-dev-site-props-table-tr-background-color, #fff);
border-top: 1px solid #c6cbd1;
}

.tr:nth-child(2n) {
background-color: var(--terra-dev-site-props-table-tr-alt-background-color, #f6f8fa);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useContext } from 'react';
import classNames from 'classnames/bind';
import { ThemeContext } from '@cerner/terra-application/lib/theme';
import Table, {
Header,
HeaderCell,
Body,
Cell,
Row,
} from 'terra-html-table';

import styles from './RulesTable.module.scss';

// Rules
const requireNoTerraBasePeerDependencyVersions = require('@cerner/package-json-lint/lib/rules/require-no-terra-base-peer-dependency-versions');
const requireNoHardCodedDependencyVersions = require('@cerner/package-json-lint/lib/rules/require-no-hard-coded-dependency-versions');
const requireThemeContextVersions = require('@cerner/package-json-lint/lib/rules/require-theme-context-versions');

const cx = classNames.bind(styles);

const rows = [
requireNoHardCodedDependencyVersions.documentation,
requireNoTerraBasePeerDependencyVersions.documentation,
requireThemeContextVersions.documentation,
];

const RulesTable = () => {
const theme = useContext(ThemeContext);

return (
<div>
<Table className={cx('table', theme.className)}>
<Header>
<HeaderCell className={cx('th')}>
Rule Name
</HeaderCell>
<HeaderCell className={cx('th')}>
Severity Type
</HeaderCell>
<HeaderCell className={cx('th')}>
Required
</HeaderCell>
<HeaderCell className={cx('th')}>
Default
</HeaderCell>
<HeaderCell className={cx('th')}>
Description
</HeaderCell>
</Header>
<Body>
{rows.map((row) => (
<Row className={cx('tr', 'props-tr')} key={row.ruleName}>
<Cell className={cx(['td', 'strong', 'props-td'])}>
{row.ruleName}
</Cell>
<Cell className={cx(['td', 'props-td'])}>
{`[${row.severityType}]`}
</Cell>
<Cell className={cx(['td', 'props-td', row.required ? ['required'] : []])}>
{row.required ? 'required' : 'optional'}
</Cell>
<Cell className={cx(['td', 'props-td'])}>
{row.default}
</Cell>
<Cell className={cx(['td', 'props-td'])}>
{row.description}
</Cell>
</Row>
))}
</Body>
</Table>
</div>
);
};

export default RulesTable;

0 comments on commit 0095a1f

Please sign in to comment.