From be25fd28b4754bcfd79e7270598c788309686b31 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 1 Nov 2022 10:47:47 +0200 Subject: [PATCH] feature: @putout/plugin-github: add set-add-and-commit (EndBug/add-and-commit#448) --- .github/workflows/nodejs.yml | 2 +- packages/plugin-github/README.md | 11 ++++- packages/plugin-github/lib/index.js | 1 + .../lib/set-add-and-commit/fixture/latest.js | 12 ++++++ .../fixture/set-add-and-commit-fix.js | 12 ++++++ .../fixture/set-add-and-commit.js | 12 ++++++ .../lib/set-add-and-commit/index.js | 40 +++++++++++++++++++ .../lib/set-add-and-commit/index.spec.js | 23 +++++++++++ .../test/fixture/set-add-and-commit-fix.js | 12 ++++++ .../test/fixture/set-add-and-commit.js | 12 ++++++ packages/plugin-github/test/github.js | 4 ++ 11 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 packages/plugin-github/lib/set-add-and-commit/fixture/latest.js create mode 100644 packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit-fix.js create mode 100644 packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit.js create mode 100644 packages/plugin-github/lib/set-add-and-commit/index.js create mode 100644 packages/plugin-github/lib/set-add-and-commit/index.spec.js create mode 100644 packages/plugin-github/test/fixture/set-add-and-commit-fix.js create mode 100644 packages/plugin-github/test/fixture/set-add-and-commit.js diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 1897b361cb..0a3bcb347d 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -42,7 +42,7 @@ jobs: - name: Typos run: typos --write-changes - name: Commit fixes - uses: EndBug/add-and-commit@v7 + uses: EndBug/add-and-commit@v9 with: message: "chore: ${{ env.NAME }}: actions: lint ☘️" - name: Coverage diff --git a/packages/plugin-github/README.md b/packages/plugin-github/README.md index 8298b01789..f06e34df2b 100644 --- a/packages/plugin-github/README.md +++ b/packages/plugin-github/README.md @@ -22,7 +22,8 @@ npm i @putout/plugin-github -D "rules": { "github/set-node-versions": "on", "github/set-checkout-version": "on", - "github/set-setup-node-version": "on" + "github/set-setup-node-version": "on", + "github/set-add-and-commit": "on" } } ``` @@ -57,6 +58,14 @@ jobs: + - uses: actions/setup-node@v3 ``` +## set-add-and-commit + +```diff + steps: +- uses: EndBug/add-and-commit@v7 ++ uses: EndBug/add-and-commit@v9 +``` + ## License MIT diff --git a/packages/plugin-github/lib/index.js b/packages/plugin-github/lib/index.js index 06de6fd4ca..a4c2058736 100644 --- a/packages/plugin-github/lib/index.js +++ b/packages/plugin-github/lib/index.js @@ -8,5 +8,6 @@ module.exports.rules = { ...getRule('set-node-versions'), ...getRule('set-checkout-version'), ...getRule('set-setup-node-version'), + ...getRule('set-add-and-commit'), }; diff --git a/packages/plugin-github/lib/set-add-and-commit/fixture/latest.js b/packages/plugin-github/lib/set-add-and-commit/fixture/latest.js new file mode 100644 index 0000000000..1768fdc541 --- /dev/null +++ b/packages/plugin-github/lib/set-add-and-commit/fixture/latest.js @@ -0,0 +1,12 @@ +__putout_processor_json({ + "jobs": { + "build": { + "runs-on": "ubuntu-latest", + "steps": [ + { + "uses": 'EndBug/add-and-commit@v9' + }, + ] + } + } +}); diff --git a/packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit-fix.js b/packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit-fix.js new file mode 100644 index 0000000000..1768fdc541 --- /dev/null +++ b/packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit-fix.js @@ -0,0 +1,12 @@ +__putout_processor_json({ + "jobs": { + "build": { + "runs-on": "ubuntu-latest", + "steps": [ + { + "uses": 'EndBug/add-and-commit@v9' + }, + ] + } + } +}); diff --git a/packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit.js b/packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit.js new file mode 100644 index 0000000000..bec4d37ee2 --- /dev/null +++ b/packages/plugin-github/lib/set-add-and-commit/fixture/set-add-and-commit.js @@ -0,0 +1,12 @@ +__putout_processor_json({ + "jobs": { + "build": { + "runs-on": "ubuntu-latest", + "steps": [ + { + "uses": "EndBug/add-and-commit@v7" + }, + ] + } + } +}); diff --git a/packages/plugin-github/lib/set-add-and-commit/index.js b/packages/plugin-github/lib/set-add-and-commit/index.js new file mode 100644 index 0000000000..ee5a6d0074 --- /dev/null +++ b/packages/plugin-github/lib/set-add-and-commit/index.js @@ -0,0 +1,40 @@ +'use strict'; + +const { + types, + operator, +} = require('putout'); + +const {traverseProperty} = require('../traverse-property'); + +const { + replaceWith, + getTemplateValues, +} = operator; + +const {StringLiteral} = types; +const checkoutNode = StringLiteral('EndBug/add-and-commit@v9'); + +module.exports.report = () => 'Latest version of EndBug/add-and-commit is missing'; + +module.exports.fix = (path) => { + replaceWith(path, checkoutNode); +}; + +module.exports.traverse = ({push}) => ({ + '__putout_processor_json(__a)'(path) { + const {__a} = getTemplateValues(path, '__putout_processor_json(__a)'); + + for (const propertyPath of traverseProperty(__a, 'uses')) { + const valuePath = propertyPath.get('value'); + const {value} = valuePath.node; + + if (value === 'EndBug/add-and-commit@v9') + continue; + + if (value === 'EndBug/add-and-commit@v7') + push(valuePath); + } + }, +}); + diff --git a/packages/plugin-github/lib/set-add-and-commit/index.spec.js b/packages/plugin-github/lib/set-add-and-commit/index.spec.js new file mode 100644 index 0000000000..09a2a0d2aa --- /dev/null +++ b/packages/plugin-github/lib/set-add-and-commit/index.spec.js @@ -0,0 +1,23 @@ +'use strict'; + +const {createTest} = require('@putout/test'); +const setAddAndCommit = require('.'); + +const test = createTest(__dirname, { + 'github/set-add-and-commit': setAddAndCommit, +}); + +test('plugin-github: set-set-add-and-commit: report', (t) => { + t.report('set-add-and-commit', 'Latest version of EndBug/add-and-commit is missing'); + t.end(); +}); + +test('plugin-github: set-set-add-and-commit: transform', (t) => { + t.transform('set-add-and-commit'); + t.end(); +}); + +test('plugin-github: set-set-add-and-commit: no report: latest', (t) => { + t.noReport('latest'); + t.end(); +}); diff --git a/packages/plugin-github/test/fixture/set-add-and-commit-fix.js b/packages/plugin-github/test/fixture/set-add-and-commit-fix.js new file mode 100644 index 0000000000..1768fdc541 --- /dev/null +++ b/packages/plugin-github/test/fixture/set-add-and-commit-fix.js @@ -0,0 +1,12 @@ +__putout_processor_json({ + "jobs": { + "build": { + "runs-on": "ubuntu-latest", + "steps": [ + { + "uses": 'EndBug/add-and-commit@v9' + }, + ] + } + } +}); diff --git a/packages/plugin-github/test/fixture/set-add-and-commit.js b/packages/plugin-github/test/fixture/set-add-and-commit.js new file mode 100644 index 0000000000..bec4d37ee2 --- /dev/null +++ b/packages/plugin-github/test/fixture/set-add-and-commit.js @@ -0,0 +1,12 @@ +__putout_processor_json({ + "jobs": { + "build": { + "runs-on": "ubuntu-latest", + "steps": [ + { + "uses": "EndBug/add-and-commit@v7" + }, + ] + } + } +}); diff --git a/packages/plugin-github/test/github.js b/packages/plugin-github/test/github.js index 1f2244f434..bbb90538a3 100644 --- a/packages/plugin-github/test/github.js +++ b/packages/plugin-github/test/github.js @@ -22,3 +22,7 @@ test('plugin-github: transform: set-setup-node-version', (t) => { t.end(); }); +test('plugin-github: transform: set-add-and-commit', (t) => { + t.transform('set-add-and-commit'); + t.end(); +});