secretlint / secretlint

Pluggable linting tool to prevent committing credential.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Next Major: v7

azu opened this issue · comments

commented

TRY CANARY!

npm install secretlint@canary @secretlint/secretlint-rule-preset-recommend@canary

ISSUE

commented

Breaking Changes

  • Require Node.js 18+
    • package code format is ES2022
  • Update Docker image based on Node.js 18
  • Update Exit Status
    • Secretlint exits with the following values
    • 0: Linting succeeded, no errors found
    • 1: Linting failed, errors found
    • 2: Unexpected error occurred, fatal error
    • Previously, these values are not defined
  • Add new "json" formatter for secretlint
    • output format is changed from old "json" formatter
  • Convert packages to Pure ESM package
    • If your scripts are CommonJS, you need to dynamic import import("@secretlint/core").
    • For command line/Docker user, No change anything!
  • Convert @secretlint/types to dual package
  • @secretlint/tester is migrated to ESM, But we can load it using dynamic import from CJS
    • @secretlint/tester uses node:test instead of Mocha
    • Also, Support URL object in snapshotDirectory option.

It means that you stil can write your rule in CommonJS.
You can migrate your snapshot testing code to secretlint v7 by following:

CommonJS Edition:

- import { snapshot } from "@secretlint/tester";
import path from "path";
import { creator as rule } from "../src/index";
+ import test from "node:test";
- describe("@secretlint/secretlint-rule-example", () => {
+ test("@secretlint/secretlint-rule-example", async (t) => {
+      const snapshot = (await import("@secretlint/tester")).snapshot;
-      snapshot({
+      await snapshot({
          defaultConfig: {
              rules: [
                  {
                      id: "@secretlint/secretlint-rule-preset-canary",
                      rule,
                      rules: [],
                      options: {},
                  },
              ],
          },
          updateSnapshot: !!process.env.UPDATE_SNAPSHOT,
          snapshotDirectory: path.join(__dirname, "snapshots"),
      }).forEach((name, test) => {
-          it(name, async function () {
+          return it(name, async (context) => {
              const status = await test();
              if (status === "skip") {
-                  this.skip();
+                  context.skip();
              }
          });
      });
  });

Of course, you can write test in ESM.

import test from "node:test";
import { snapshot } "@secretlint/teter";
import { creator as rule } from "../src/index.js";
test("@secretlint/secretlint-rule-example", async (t) => {
    return snapshot({
        defaultConfig: {
            rules: [
                {
                    id: "@secretlint/secretlint-rule-example",
                    rule,
                    options: {},
                },
            ],
        },
        updateSnapshot: !!process.env.UPDATE_SNAPSHOT,
        snapshotDirectory: new URL("snapshots", import.meta.url),
    }).forEach((name, test) => {
        return t.test(name, async (context) => {
            const status = await test();
            if (status === "skip") {
                context.skip();
            }
        });
    });
});

And run tests:

$ node --test test/index.test.js
# or
$ node --loader ts-node/esm --test test/index.test.ts

For more details, see https://github.com/secretlint/secretlint/blob/master/docs/secretlint-rule.md