npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dclint

v1.0.1

Published

A command-line tool for validating and enforcing best practices in Docker Compose files.

Downloads

700

Readme

Docker Compose Linter

Latest NPM Release Version Latest Docker Hub Release Version Code Coverage Score Codacy Code Quality Score Conventional Commits

Note: Docker Compose configurations vary greatly between different projects and setups. While DCLint is stable, there may be edge cases or unique setups that cause issues. If you encounter any problems or have suggestions, please feel free to open an issue or submit a pull request. Your feedback is highly appreciated!

Docker Compose Linter (DCLint) is a utility designed to analyze, validate and fix Docker Compose files. It helps identify errors, style violations, and potential issues in Docker Compose files, ensuring your configurations are robust, maintainable, and free from common pitfalls.

Features

  • Error Detection: Identifies syntax errors and common issues in Docker Compose files.
  • Style Enforcement: Enforces best practices and style guidelines for maintainable configurations.
  • Flexible Integration: Can be used locally, in Docker, or integrated into CI/CD pipelines.
  • Configurable Rules: Customize the linter's behavior and rules according to your project's needs.
  • Auto-fixable Rules: Some rules include an auto-fix mode, allowing you to automatically format and correct certain issues in your files.
  • Comments Support: After automated sorting and fixing, comments remain in the correct place, ensuring no important information is lost during the formatting process.

Getting Started

Installation with Node.js

You can install Docker Compose Linter locally in your project or use it directly with npx.

Note: DCLint requires Node.js version 18 or higher.

To install it locally:

npm install --save-dev dclint

Running the Linter with npx

If you prefer not to install it globally, you can run the linter directly using npx:

npx dclint .

This command will lint your Docker Compose files in the current directory.

Linting Specific Files

To lint a specific Docker Compose file or a directory containing such files, specify the path relative to your project directory:

npx dclint /path/to/docker-compose.yml

Display Help and Options

To display help and see all available options:

npx dclint -h

For more details about available options and formatters, please refer to the CLI Reference and Formatters Reference.

Usage with Docker

Pull the Docker Image

First, pull the Docker image from the repository:

docker pull zavoloklom/dclint

Run the Linter in Docker

To lint your Docker Compose files, use the following command. This command mounts your current working directory ${PWD} to the /app directory inside the container and runs the linter:

docker run -t --rm -v ${PWD}:/app zavoloklom/dclint .

Linting Specific Files in Docker

If you want to lint a specific Docker Compose file or a directory containing such files, specify the path relative to your project directory:

docker run -t --rm -v ${PWD}:/app zavoloklom/dclint /app/path/to/docker-compose.yml

Display Help in Docker

To display help and see all available options:

docker run -t --rm -v ${PWD}:/app zavoloklom/dclint -h

For more information about available options and formatters, please refer to the CLI Reference and Formatters Reference.

Rules and Errors

Docker Compose Linter includes set of rules to ensure your Docker Compose files adhere to best practices. Detailed documentation for each rule and the errors that can be detected by the linter is available here:

DCLint uses the yaml library for linting and formatting Docker Compose files. This ensures that any configuration files you check are compliant with YAML standards. Before any rule checks are applied, two important validations are performed, which cannot be disabled - YAML Validity Check and Docker Compose Schema Validation.

Configuration

DCLint allows you to customize the set of rules used during linting to fit your project's specific needs. You can configure which rules are applied, their severity levels, and additional behavior settings using a configuration file.

Supported Configuration File Formats

DCLint supports flexible configuration options through the use of cosmiconfig. This means you can use various formats to configure the linter, including JSON, YAML, and JavaScript files.

For example:

  • .dclintrc (JSON, YAML, or JavaScript)
  • dclint.config.js (JavaScript)
  • A dclint key inside your package.json

Example Configuration File

Here is an example of a configuration file using JSON format:

{
  "rules": {
    "no-version-field": 0,
    "require-quotes-in-ports": 1,
    "services-alphabetical-order": 2
  },
  "quiet": false,
  "debug": true,
  "exclude": [
    "tests"
  ]
}
  • rules: Customize which rules to apply and their severity levels (0 - Disabled, 1 - Warning, 2 - Error).
  • quiet: Suppresses non-error output if set to true.
  • debug: Enables debug mode with additional output if set to true.
  • exclude: Specifies files or directories to exclude from linting.

Configure Rules

In addition to enabling or disabling rules, some rules may support custom parameters to tailor them to your specific needs. For example, the require-quotes-in-ports rule allows you to configure whether single or double quotes should be used around port numbers. You can configure it like this:

{
  "rules": {
    "require-quotes-in-ports": [
      2,
      {
        "quoteType": "double"
      }
    ]
  }
}

In this example, the require-quotes-in-ports rule is enabled at the error level and configured to enforce double quotes around ports.

Integrate into CI/CD Pipeline

Automate linting as part of your CI/CD pipeline by adding the Docker run command to your pipeline script. This ensures that your Docker Compose files are always checked for errors before deployment.

GitLab CI Example

lint-docker-compose:
  image: docker:latest
  script:
    - docker run --rm -i -v ${CI_PROJECT_DIR}:/app zavoloklom/dclint . -f codeclimate -o gl-codequality.json
  artifacts:
    reports:
      codequality: gl-codequality.json

Alternatives

Consider these alternative tools for Docker Compose linting and validation:

And this tools for Docker Compose formatting and fixing:

Contributing

If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.

If you'd like to contribute to this project, please read through the CONTRIBUTING.md file.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project, you agree to abide by its terms.

Changelog

The changelog is automatically generated based on semantic-release and conventional commits.

See the CHANGELOG.md file for detailed lists of changes for each version.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Contact

If you have any questions or suggestions, feel free to reach out: