diff --git a/.eslintrc.json b/.eslintrc.json index b880603..8f64d1e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,7 +4,7 @@ }, "extends": [ "plugin:n/recommended", - "plugin:putout/safe+align" + "plugin:putout/esm" ], "plugins": [ "putout", diff --git a/.github/workflows/nodejs-pr.yml b/.github/workflows/nodejs-pr.yml index e80f683..7d21a55 100644 --- a/.github/workflows/nodejs-pr.yml +++ b/.github/workflows/nodejs-pr.yml @@ -12,17 +12,19 @@ jobs: - 20.x steps: - uses: actions/checkout@v3 + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - name: Install - run: npm install + run: bun i --no-save - name: Lint run: npm run lint - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable + - name: Install Rust + run: rustup update - uses: actions/cache@v3 with: path: | diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 268811c..d05377c 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -17,17 +17,19 @@ jobs: with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} + - uses: oven-sh/setup-bun@v1 + with: + bun-version: latest - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} - name: Install - run: npm install + run: bun i --no-save - name: Lint run: npm run fix:lint - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable + - name: Install Rust + run: rustup update - uses: actions/cache@v3 with: path: | diff --git a/.madrun.js b/.madrun.js index cb51ba6..9f43f31 100644 --- a/.madrun.js +++ b/.madrun.js @@ -3,7 +3,7 @@ import {run} from 'madrun'; export default { 'test': () => `tape packages/**/*.spec.js`, 'coverage': async () => `escover ${await run('test')}`, - 'lint': () => `putout .`, + 'lint': () => `putout . --rulesdir rules`, 'fix:lint': () => run('lint', '--fix'), 'build': () => 'node .build.js', 'wisdom': () => run(['lint', 'coverage', 'build']), diff --git a/.npmignore b/.npmignore index efb5528..78ecede 100644 --- a/.npmignore +++ b/.npmignore @@ -6,4 +6,5 @@ dist fixture coverage examples +rules diff --git a/.putout.json b/.putout.json index e7ab631..47cae6f 100644 --- a/.putout.json +++ b/.putout.json @@ -1,6 +1,7 @@ { "rules": { - "putout": "on" + "putout": "on", + "putout/apply-namaspace-specifier": "off" }, "ignore": [ "examples/*.js" diff --git a/README.md b/README.md index 7e9ffeb..3866945 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ When you need to compile **Goldstein** to **JavaScript** use: ```js import {compile} from 'goldstein'; -compile(` +await compile(` fn hello() { guard text !== "world" else { return "" diff --git a/bin/gs.js b/bin/gs.js index eaedb70..75cf616 100644 --- a/bin/gs.js +++ b/bin/gs.js @@ -5,7 +5,7 @@ import { readFileSync, writeFileSync, unlinkSync, -} from 'fs'; +} from 'node:fs'; import {compile} from '../packages/goldstein/index.js'; const [arg] = process.argv.slice(2); diff --git a/package.json b/package.json index a51b73b..322501c 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,8 @@ "runsome": "^1.0.0", "supertape": "^8.0.1", "typescript": "^5.0.3", - "zenload": "^2.0.0" + "zenload": "^2.0.0", + "rules": "./rules/goldstein" }, "engines": { "node": ">=16" diff --git a/rules/goldstein/.eslintrc.json b/rules/goldstein/.eslintrc.json new file mode 100644 index 0000000..326cd47 --- /dev/null +++ b/rules/goldstein/.eslintrc.json @@ -0,0 +1,11 @@ +{ + "root": true, + "extends": [ + "plugin:n/recommended", + "plugin:putout/esm" + ], + "plugins": [ + "n", + "putout" + ] +} diff --git a/rules/goldstein/.gitignore b/rules/goldstein/.gitignore new file mode 100644 index 0000000..7554640 --- /dev/null +++ b/rules/goldstein/.gitignore @@ -0,0 +1,6 @@ +node_modules +*.swp +yarn-error.log + +coverage +.idea diff --git a/rules/goldstein/.madrun.mjs b/rules/goldstein/.madrun.mjs new file mode 100644 index 0000000..1e5f518 --- /dev/null +++ b/rules/goldstein/.madrun.mjs @@ -0,0 +1,13 @@ +import {run} from 'madrun'; + +export default { + 'prepublishOnly': () => run(['lint', 'test']), + 'test': () => `tape 'test/*.js' 'lib/**/*.spec.js'`, + 'watch:test': async () => `nodemon -w lib -x ${await run('test')}`, + 'lint': () => 'putout .', + 'fresh:lint': async () => await run('lint', '--fresh'), + 'lint:fresh': async () => await run('lint', '--fresh'), + 'fix:lint': async () => await run('lint', '--fix'), + 'coverage': async () => `c8 ${await run('test')}`, + 'report': () => 'c8 report --reporter=lcov', +}; diff --git a/rules/goldstein/.npmignore b/rules/goldstein/.npmignore new file mode 100644 index 0000000..da7de74 --- /dev/null +++ b/rules/goldstein/.npmignore @@ -0,0 +1,6 @@ +.* +*.spec.js +test +fixture +yarn-error.log +coverage diff --git a/rules/goldstein/.nycrc.json b/rules/goldstein/.nycrc.json new file mode 100644 index 0000000..b1ae311 --- /dev/null +++ b/rules/goldstein/.nycrc.json @@ -0,0 +1,14 @@ +{ + "check-coverage": true, + "all": true, + "exclude": [ + "**/*.spec.*", + "**/fixture", + "test", + ".*.*" + ], + "branches": 100, + "lines": 100, + "functions": 100, + "statements": 100 +} diff --git a/rules/goldstein/LICENSE b/rules/goldstein/LICENSE new file mode 100644 index 0000000..eaec9a1 --- /dev/null +++ b/rules/goldstein/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) coderaiser + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/rules/goldstein/README.md b/rules/goldstein/README.md new file mode 100644 index 0000000..ab4a87d --- /dev/null +++ b/rules/goldstein/README.md @@ -0,0 +1,53 @@ +# @putout/plugin-goldstein [![NPM version][NPMIMGURL]][NPMURL] + +[NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-goldstein.svg?style=flat&longCache=true +[NPMURL]: https://npmjs.org/package/@putout/plugin-goldstein "npm" + +> JavaScript with no limits 🀫. +> +> (c) [**Goldstein**](https://github.com/coderaiser/goldstein) + +🐊[**Putout**](https://github.com/coderaiser/putout) plugin adds ability to fix issues with +**Madrun** config file. + +## Install + +``` +npm i putout @putout/plugin-goldstein -D +``` + +## Rules + +```json +{ + "rules": { + "goldstein/convert-t-compile-to-compile": "on" + } +} +``` + +## convert-t-compile-to-compile + +Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/a10dd187dc3c6be8df110a8481b9d9bc/3abfc0879aad5ccff5c8e4851cb3ad06270c986e). + +### ❌ Example of incorrect code + +```js +test('goldstein: keyword: import', async ({compile}) => { + await compile('import'); + t.end(); +}); +``` + +### βœ… Example of correct code + +```js +test('goldstein: keyword: import', async ({compile}) => { + await compile('import'); + t.end(); +}); +``` + +## License + +MIT diff --git a/rules/goldstein/lib/convert-t-compile-to-compile/fixture/convert-t-compile-to-compile-fix.js b/rules/goldstein/lib/convert-t-compile-to-compile/fixture/convert-t-compile-to-compile-fix.js new file mode 100644 index 0000000..0286bbd --- /dev/null +++ b/rules/goldstein/lib/convert-t-compile-to-compile/fixture/convert-t-compile-to-compile-fix.js @@ -0,0 +1,3 @@ +test('goldstein: keyword: import', async ({compile}) => { + await compile('import'); +}); diff --git a/rules/goldstein/lib/convert-t-compile-to-compile/fixture/convert-t-compile-to-compile.js b/rules/goldstein/lib/convert-t-compile-to-compile/fixture/convert-t-compile-to-compile.js new file mode 100644 index 0000000..a48762d --- /dev/null +++ b/rules/goldstein/lib/convert-t-compile-to-compile/fixture/convert-t-compile-to-compile.js @@ -0,0 +1,5 @@ +test('goldstein: keyword: import', (t) => { + t.compile('import'); + t.end(); +}); + diff --git a/rules/goldstein/lib/convert-t-compile-to-compile/index.js b/rules/goldstein/lib/convert-t-compile-to-compile/index.js new file mode 100644 index 0000000..80a6060 --- /dev/null +++ b/rules/goldstein/lib/convert-t-compile-to-compile/index.js @@ -0,0 +1,30 @@ +import {types} from 'putout'; + +const { + ObjectProperty, + ObjectPattern, + Identifier, +} = types; + +const COMPUTED = false; +const SHORTHAND = true; + +export const report = () => `Use 'compile()' instead of 't.compile'`; + +export const replace = () => ({ + 't.end()': '', + 't.compile(__a)': (vars, path) => { + const {block} = path.scope; + + path.scope.block.async = true; + + const id = Identifier('compile'); + const param = ObjectPattern([ + ObjectProperty(id, id, COMPUTED, SHORTHAND), + ]); + + block.params = [param]; + + return 'await compile(__a)'; + }, +}); diff --git a/rules/goldstein/lib/convert-t-compile-to-compile/index.spec.js b/rules/goldstein/lib/convert-t-compile-to-compile/index.spec.js new file mode 100644 index 0000000..1d66d17 --- /dev/null +++ b/rules/goldstein/lib/convert-t-compile-to-compile/index.spec.js @@ -0,0 +1,19 @@ +import {createTest} from '@putout/test'; +import * as plugin from './index.js'; + +const test = createTest(import.meta.url, { + printer: 'putout', + plugins: [ + ['convert-t-compile-to-compile', plugin], + ], +}); + +test('rules: convert-t-compile-to-compile: report', (t) => { + t.report('convert-t-compile-to-compile', `Use 'compile()' instead of 't.compile'`); + t.end(); +}); + +test('rules: convert-t-compile-to-compile: transform', (t) => { + t.transform('convert-t-compile-to-compile'); + t.end(); +}); diff --git a/rules/goldstein/lib/index.js b/rules/goldstein/lib/index.js new file mode 100644 index 0000000..45fb99f --- /dev/null +++ b/rules/goldstein/lib/index.js @@ -0,0 +1,5 @@ +import * as convertTCompileToCompile from './convert-t-compile-to-compile/index.js'; + +export const rules = { + 'convert-t-compile-to-compile': convertTCompileToCompile, +}; diff --git a/rules/goldstein/package.json b/rules/goldstein/package.json new file mode 100644 index 0000000..0880693 --- /dev/null +++ b/rules/goldstein/package.json @@ -0,0 +1,52 @@ +{ + "name": "@putout/plugin-goldstein", + "version": "1.0.0", + "type": "module", + "author": "coderaiser (https://github.com/coderaiser)", + "description": "🐊Putout plugin adds ability to transform madrun scripts", + "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-madrun#readme", + "main": "lib/index.js", + "release": false, + "tag": false, + "changelog": false, + "repository": { + "type": "git", + "url": "git://github.com/coderaiser/putout.git" + }, + "scripts": { + "test": "madrun test", + "watch:test": "madrun watch:test", + "lint": "madrun lint", + "fresh:lint": "madrun fresh:lint", + "lint:fresh": "madrun lint:fresh", + "fix:lint": "madrun fix:lint", + "coverage": "madrun coverage", + "report": "madrun report" + }, + "dependencies": {}, + "keywords": [ + "putout", + "putout-plugin", + "plugin", + "madrun" + ], + "devDependencies": { + "@putout/test": "^7.0.0", + "c8": "^8.0.0", + "eslint": "^8.0.1", + "eslint-plugin-n": "^16.0.0", + "eslint-plugin-putout": "^19.0.0", + "madrun": "^9.0.0", + "nodemon": "^3.0.1" + }, + "peerDependencies": { + "putout": ">=31" + }, + "license": "MIT", + "engines": { + "node": ">=16" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/rules/goldstein/test/fixture/convert-t-compile-to-compile-fix.js b/rules/goldstein/test/fixture/convert-t-compile-to-compile-fix.js new file mode 100644 index 0000000..4e12c19 --- /dev/null +++ b/rules/goldstein/test/fixture/convert-t-compile-to-compile-fix.js @@ -0,0 +1,4 @@ +test('goldstein: keyword: import', async ({compile}) => { + await compile('import'); + t.end(); +}); diff --git a/rules/goldstein/test/fixture/convert-t-compile-to-compile.js b/rules/goldstein/test/fixture/convert-t-compile-to-compile.js new file mode 100644 index 0000000..a48762d --- /dev/null +++ b/rules/goldstein/test/fixture/convert-t-compile-to-compile.js @@ -0,0 +1,5 @@ +test('goldstein: keyword: import', (t) => { + t.compile('import'); + t.end(); +}); + diff --git a/rules/goldstein/test/goldstein.js b/rules/goldstein/test/goldstein.js new file mode 100644 index 0000000..4ae964b --- /dev/null +++ b/rules/goldstein/test/goldstein.js @@ -0,0 +1,14 @@ +import {createTest} from '@putout/test'; +import * as goldstein from '../lib/index.js'; + +const test = createTest(import.meta.url, { + printer: 'putout', + plugins: [ + ['goldstein', goldstein], + ], +}); + +test('plugin-goldstein: transform: convert-t-compile-to-compile', (t) => { + t.transform('convert-t-compile-to-compile'); + t.end(); +});