Skip to content

Commit

Permalink
docs: update rules descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zavoloklom committed Dec 15, 2024
1 parent 292c6f9 commit 1fdbd1f
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 57 deletions.
48 changes: 33 additions & 15 deletions docs/rules.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,61 @@
# Rules Reference

DCLint categorizes its rules into several categories to help you ensure that your Docker Compose files meet specific
DCLint categorizes rules into several categories to help you ensure that your Docker Compose files meet specific
standards.

In the tables below:

- 🔴 — Error. Indicates a critical issue. The exit code will be non-zero if this occurs.
- 🟡 — Warning. Indicates a non-critical issue. The exit code will remain zero.
- 🔧 — Auto-fixable. Issues reported by this rule are automatically fixable.
- ⚙️ — Configurable. Behavior of the rule can be adjusted using options.

## Style

These rules enforce consistency in formatting and structure to ensure that your Docker Compose files are easy to read
and maintain. They focus on best practices related to code style, such as proper ordering of fields and avoiding
unnecessary complexity.

- [Volumes No Quotes Rule](./rules/no-quotes-in-volumes-rule.md)
- [Service Dependencies Alphabetical Order Rule](./rules/service-dependencies-alphabetical-order-rule.md)
- [Service Keys Order Rule](./rules/service-keys-order-rule.md)
- [Service Ports Alphabetical Order Rule](./rules/service-ports-alphabetical-order-rule.md)
- [Services Alphabetical Order Rule](./rules/services-alphabetical-order-rule.md)
- [Top-Level Properties Order Rule](./rules/top-level-properties-order-rule.md)
| Name | Description | |
| -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------- | -------- |
| [No Quotes In Volumes](./rules/no-quotes-in-volumes-rule.md) | Values in the `volumes` section should not be enclosed in quotes. | 🟡 🔧 |
| [Service Dependencies Alphabetical Order](./rules/service-dependencies-alphabetical-order-rule.md) | Services in the `depends_on` section should be sorted alphabetically. | 🟡 🔧 |
| [Service Keys Order](./rules/service-keys-order-rule.md) | Keys within each service should follow a specific order. | 🟡 🔧 ⚙️ |
| [Service Ports Alphabetical Order](./rules/service-ports-alphabetical-order-rule.md) | The list of ports in a service should be sorted alphabetically. | 🟡 🔧 |
| [Services Alphabetical Order](./rules/services-alphabetical-order-rule.md) | Services should be sorted alphabetically. | 🟡 🔧 |
| [Top Level Properties Order](./rules/top-level-properties-order-rule.md) | Top-level properties should follow a specific order. | 🟡 🔧 ⚙️ |

## Security

Security rules focus on identifying potential vulnerabilities in your Docker Compose files. These rules help prevent
common security risks, such as exposing sensitive data or using unsafe configurations.

- [No Duplicate Container Names Rule](./rules/no-duplicate-container-names-rule.md)
- [No Duplicate Exported Ports Rule](./rules/no-duplicate-exported-ports-rule.md)
- [Service Container Name Regex Rule](./rules/service-container-name-regex-rule.md)
- [Service Image Require Explicit Tag Rule](./rules/service-image-require-explicit-tag-rule.md)
| Name | Description | |
| ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | ----- |
| [No Duplicate Container Names](./rules/no-duplicate-container-names-rule.md) | Container names must be unique to prevent conflicts and ensure proper container management. | 🔴 |
| [No Duplicate Exported Ports](./rules/no-duplicate-exported-ports-rule.md) | Exported ports must be unique to avoid conflicts. | 🔴 |
| [No Unbound Port Interfaces](./rules/no-unbound-port-interfaces-rule.md) | Exported ports must be bound to specific interfaces to avoid unintentional exposure. | 🔴 |
| [Service Container Name Regex](./rules/service-container-name-regex-rule.md) | Container names must match the pattern `/^[a-zA-Z0-9][a-zA-Z0-9_.-]+$/` to comply with Docker naming conventions. | 🔴 |
| [Service Image Require Explicit Tag](./rules/service-image-require-explicit-tag-rule.md) | Services must use a specific image tag instead of "latest", "stable" or no tag. | 🔴 ⚙️ |

## Best Practice

These rules enforce general Docker Compose best practices, guiding you towards configurations that are known to work
well. They help avoid pitfalls and ensure your configurations are reliable and maintainable.

- [No Build and Image Rule](./rules/no-build-and-image-rule.md)
- [No Version Field Rule](./rules/no-version-field-rule.md)
- [Required Project Name Field Rule](./rules/require-project-name-field-rule.md)
- [Require Quotes in Ports Rule](./rules/require-quotes-in-ports-rule.md)
| Name | Description | |
| ------------------------------------------------------------------------ | -------------------------------------------------------------------- | -------- |
| [No Build And Image](./rules/no-build-and-image-rule.md) | Each service must use either `build` or `image`, not both. | 🔴 ⚙️ |
| [No Version Field](./rules/no-version-field-rule.md) | The `version` field must be absent in the configuration. | 🔴 🔧 |
| [Require Project Name Field](./rules/require-project-name-field-rule.md) | The `name` field should be included in the configuration. | 🟡 |
| [Require Quotes In Ports](./rules/require-quotes-in-ports-rule.md) | Ports in `ports` and `expose` sections should be enclosed in quotes. | 🟡 🔧 ⚙️ |

## Performance

Performance rules are designed to optimize the runtime behavior of your Docker Compose setup. They identify
configurations that could negatively impact performance, such as inefficient resource usage or misconfigurations that
may lead to slower application performance.

| Name | Description | |
| ---- | ----------- | --- |
| | | |
5 changes: 2 additions & 3 deletions src/rules/no-build-and-image-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export default class NoBuildAndImageRule implements LintRule {
public severity: LintRuleSeverity = 'major';

public meta: RuleMeta = {
description:
'Ensure that each service uses either "build" or "image", but not both, to prevent ambiguity in Docker Compose configurations.',
description: 'Each service must use either `build` or `image`, not both.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/no-build-and-image-rule.md',
};

Expand All @@ -46,7 +45,7 @@ export default class NoBuildAndImageRule implements LintRule {

// eslint-disable-next-line class-methods-use-this
public getMessage({ serviceName }: { serviceName: string }): string {
return `Service "${serviceName}" is using both "build" and "image". Use either "build" or "image" but not both.`;
return `Service "${serviceName}" is using both "build" and "image". Use one of them, but not both.`;
}

public check(context: LintContext): LintMessage[] {
Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-duplicate-container-names-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export default class NoDuplicateContainerNamesRule implements LintRule {
public severity: LintRuleSeverity = 'critical';

public meta: RuleMeta = {
description:
'Ensure that container names in Docker Compose are unique to prevent name conflicts and ensure proper container management.',
description: 'Container names must be unique to prevent conflicts and ensure proper container management.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/no-duplicate-container-names-rule.md',
};

Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-duplicate-exported-ports-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export default class NoDuplicateExportedPortsRule implements LintRule {
public severity: LintRuleSeverity = 'critical';

public meta: RuleMeta = {
description:
'Ensure that exported ports in Docker Compose are unique to prevent port conflicts and ensure proper network behavior.',
description: 'Exported ports must be unique to avoid conflicts.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/no-duplicate-exported-ports-rule.md',
};

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-quotes-in-volumes-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class NoQuotesInVolumesRule implements LintRule {
public severity: LintRuleSeverity = 'info';

public meta: RuleMeta = {
description: 'Ensure that quotes are not used in volume names in Docker Compose files.',
description: 'Values in the `volumes` section should not be enclosed in quotes.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/no-quotes-in-volumes-rule.md',
};

Expand Down
3 changes: 1 addition & 2 deletions src/rules/no-unbound-port-interfaces-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export default class NoUnboundPortInterfacesRule implements LintRule {
public severity: LintRuleSeverity = 'major';

public meta: RuleMeta = {
description:
'Ensure that exported ports in Docker Compose are bound to specific Interfaces to prevent unintentional exposing services to the network.',
description: 'Exported ports must be bound to specific interfaces to avoid unintentional exposure.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/no-unbound-port-interfaces-rule.md',
};

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-version-field-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class NoVersionFieldRule implements LintRule {
public severity: LintRuleSeverity = 'minor';

public meta: RuleMeta = {
description: 'Ensure that the "version" field is not present in the Docker Compose file.',
description: 'The `version` field must be absent in the configuration.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/no-version-field-rule.md',
};

Expand Down
2 changes: 1 addition & 1 deletion src/rules/require-project-name-field-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class RequireProjectNameFieldRule implements LintRule {
public severity: LintRuleSeverity = 'minor';

public meta: RuleMeta = {
description: 'Ensure that the "name" field is present in the Docker Compose file.',
description: 'The `name` field should be included in the configuration.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/require-project-name-field-rule.md',
};

Expand Down
2 changes: 1 addition & 1 deletion src/rules/require-quotes-in-ports-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class RequireQuotesInPortsRule implements LintRule {
public severity: LintRuleSeverity = 'minor';

public meta: RuleMeta = {
description: 'Ensure that ports (in `ports` and `expose` sections) are enclosed in quotes in Docker Compose files.',
description: 'Ports in `ports` and `expose` sections should be enclosed in quotes.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/require-quotes-in-ports-rule.md',
};

Expand Down
9 changes: 3 additions & 6 deletions src/rules/service-container-name-regex-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export default class ServiceContainerNameRegexRule implements LintRule {

public severity: LintRuleSeverity = 'critical';

public message = 'Container names must match the regex pattern [a-zA-Z0-9][a-zA-Z0-9_.-]+.';
// see https://docs.docker.com/reference/compose-file/services/#container_name
private static readonly containerNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9_.-]+$/;

public meta: RuleMeta = {
description:
'Ensure that container names in Docker Compose match the required regex pattern to avoid invalid names.',
description: `Container names must match the pattern \`${ServiceContainerNameRegexRule.containerNameRegex}\` to comply with Docker naming conventions.`,
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/service-container-name-regex-rule.md',
};

Expand All @@ -34,9 +34,6 @@ export default class ServiceContainerNameRegexRule implements LintRule {
return `Service "${serviceName}" has an invalid container name "${containerName}". It must match the regex pattern ${ServiceContainerNameRegexRule.containerNameRegex}.`;
}

// see https://docs.docker.com/reference/compose-file/services/#container_name
private static readonly containerNameRegex = /^[a-zA-Z0-9][a-zA-Z0-9_.-]+$/;

public check(context: LintContext): LintMessage[] {
const errors: LintMessage[] = [];
const parsedDocument = parseDocument(context.sourceCode);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/service-dependencies-alphabetical-order-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class ServiceDependenciesAlphabeticalOrderRule implements LintRul
public severity: LintRuleSeverity = 'info';

public meta: RuleMeta = {
description: 'Ensure that the services listed in the depends_on directive are sorted alphabetically.',
description: 'Services in the `depends_on` section should be sorted alphabetically.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/service-dependencies-alphabetical-order-rule.md',
};

Expand Down
3 changes: 1 addition & 2 deletions src/rules/service-image-require-explicit-tag-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ export default class ServiceImageRequireExplicitTagRule implements LintRule {
public severity: LintRuleSeverity = 'major';

public meta: RuleMeta = {
description:
'Avoid using unspecific image tags like "latest" or "stable" in Docker Compose files to prevent unpredictable behavior. Specify a specific image version.',
description: 'Services must use a specific image tag instead of "latest", "stable" or no tag.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/service-image-require-explicit-tag-rule.md',
};

Expand Down
4 changes: 1 addition & 3 deletions src/rules/service-keys-order-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ export default class ServiceKeysOrderRule implements LintRule {

public severity: LintRuleSeverity = 'minor';

public message = 'Keys within each service should follow the predefined order.';

public meta: RuleMeta = {
description: 'Ensure that keys within each service in the Docker Compose file are ordered correctly.',
description: 'Keys within each service should follow a specific order.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/service-keys-order-rule.md',
};

Expand Down
2 changes: 1 addition & 1 deletion src/rules/service-ports-alphabetical-order-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class ServicePortsAlphabeticalOrderRule implements LintRule {
public severity: LintRuleSeverity = 'info';

public meta: RuleMeta = {
description: 'Ensure that the list of ports in the Docker Compose service is alphabetically sorted.',
description: 'The list of ports in a service should be sorted alphabetically.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/service-ports-alphabetical-order-rule.md',
};

Expand Down
4 changes: 1 addition & 3 deletions src/rules/services-alphabetical-order-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ export default class ServicesAlphabeticalOrderRule implements LintRule {

public severity: LintRuleSeverity = 'minor';

public message = 'Services should be listed in alphabetical order.';

public meta: RuleMeta = {
description: 'Ensure that services in the Docker Compose file are listed in alphabetical order.',
description: 'Services should be sorted alphabetically.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/services-alphabetical-order-rule.md',
};

Expand Down
4 changes: 1 addition & 3 deletions src/rules/top-level-properties-order-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ export default class TopLevelPropertiesOrderRule implements LintRule {

public severity: LintRuleSeverity = 'major';

public message = 'Top-level properties should follow the predefined order.';

public meta: RuleMeta = {
description: 'Ensure that top-level properties in the Docker Compose file are ordered correctly.',
description: 'Top-level properties should follow a specific order.',
url: 'https://github.com/zavoloklom/docker-compose-linter/blob/main/docs/rules/top-level-properties-order-rule.md',
};

Expand Down
14 changes: 4 additions & 10 deletions tests/rules/no-build-and-image-rule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,10 @@ test('NoBuildAndImageRule: should return a warning when both "build" and "image"
'There should be two warnings when both "build" and "image" are used and checkPullPolicy is false.',
);

const expectedMessages = [
'Service "web" is using both "build" and "image". Use either "build" or "image" but not both.',
'Service "db" is using both "build" and "image". Use either "build" or "image" but not both.',
];
const expectedMessages = [rule.getMessage({ serviceName: 'web' }), rule.getMessage({ serviceName: 'db' })];

errors.forEach((error, index) => {
t.true(error.message.includes(expectedMessages[index]));
t.true(error.message === expectedMessages[index]);
});
});

Expand All @@ -90,13 +87,10 @@ test('NoBuildAndImageRule: should return a warning when both "build" and "image"
'There should be two warnings when both "build" and "image" are used and checkPullPolicy is false.',
);

const expectedMessages = [
'Service "web" is using both "build" and "image". Use either "build" or "image" but not both.',
'Service "db" is using both "build" and "image". Use either "build" or "image" but not both.',
];
const expectedMessages = [rule.getMessage({ serviceName: 'web' }), rule.getMessage({ serviceName: 'db' })];

errors.forEach((error, index) => {
t.true(error.message.includes(expectedMessages[index]));
t.true(error.message === expectedMessages[index]);
});
});

Expand Down

0 comments on commit 1fdbd1f

Please sign in to comment.