logo
0
2
WeChat Login

logo
End-of-Line Checker Plugin

The End-of-Line Checker Plugin is used to verify whether files end with a newline character. Ending file content with a newline is an important coding convention for the following reasons:

  1. POSIX Standard Definition. According to the POSIX (Portable Operating System Interface) standard:
    • Every line in a text file must end with a newline character \n
    • The last line of a file must also end with a newline character
    • A line that does not end with a newline is considered an "incomplete line"
  2. Avoiding Compiler/Interpreter Warnings. For example, GCC, the Go compiler, and Git diff display may show special warnings and messages for files without a trailing newline.
  3. Command-Line Tool Compatibility. Many Unix tools assume files end with a newline. Non-compliant files may cause inaccurate display or unexpected results.
  4. Safe File Concatenation. When merging multiple files, the absence of a trailing newline causes content to be concatenated without separation.

Note: Binary files (such as .png, .pdf, .zip, etc.) are not checked by the plugin — they are automatically skipped.

Usage

Add the following to your .cnb.yml:

$:
  pull_request:
    eof_check:
      stages:
      - name: check end of line
        image: cnbcool/eof-newline-checker:latest
        settings:
          mode: all
          ignore:
          - "*.svg"
          - ".cnb/web_trigger.yml"
          focus:
          - "*.md"
          - ".gitignore"
          - "**/Dockerfile*"

Image Note: The plugin provides two available image addresses. You can choose based on your network environment:

  • cnbcool/eof-newline-checker:latest (Recommended, from DockerHub)
  • docker.cnb.cool/cnb/plugins/cnbcool/eof-newline-checker:latest (from CNB Registry)

Both images are identical in content. You can use either one.

Parameter explanation:

  1. mode: Check mode. This is an optional parameter. Supported values:

    • all: Full check. This is the default value. Checks whether all files end with a newline character.
    • change: Incremental check. Only checks files that have been changed; other files are not checked.
  2. ignore: Ignore list. This is an optional parameter that specifies files to exclude from the check. Supports glob patterns.

  3. focus: Focus list. This is an optional parameter that specifies files to include in the check. Regardless of the mode value, files listed in focus will always be checked. If a file matches both ignore and focus, focus takes priority — the file will be checked. If focus matches a binary file, the plugin will report an error because binary files cannot be checked for trailing newlines.