Skip to content

Commit

Permalink
feature: rules: add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Aug 28, 2023
1 parent 8a8dd67 commit 86c5230
Show file tree
Hide file tree
Showing 25 changed files with 282 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
},
"extends": [
"plugin:n/recommended",
"plugin:putout/safe+align"
"plugin:putout/esm"
],
"plugins": [
"putout",
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/nodejs-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .madrun.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']),
Expand Down
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dist
fixture
coverage
examples
rules

3 changes: 2 additions & 1 deletion .putout.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"rules": {
"putout": "on"
"putout": "on",
"putout/apply-namaspace-specifier": "off"
},
"ignore": [
"examples/*.js"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
2 changes: 1 addition & 1 deletion bin/gs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions rules/goldstein/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"root": true,
"extends": [
"plugin:n/recommended",
"plugin:putout/esm"
],
"plugins": [
"n",
"putout"
]
}
6 changes: 6 additions & 0 deletions rules/goldstein/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
*.swp
yarn-error.log

coverage
.idea
13 changes: 13 additions & 0 deletions rules/goldstein/.madrun.mjs
Original file line number Diff line number Diff line change
@@ -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',
};
6 changes: 6 additions & 0 deletions rules/goldstein/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.*
*.spec.js
test
fixture
yarn-error.log
coverage
14 changes: 14 additions & 0 deletions rules/goldstein/.nycrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"check-coverage": true,
"all": true,
"exclude": [
"**/*.spec.*",
"**/fixture",
"test",
".*.*"
],
"branches": 100,
"lines": 100,
"functions": 100,
"statements": 100
}
21 changes: 21 additions & 0 deletions rules/goldstein/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
53 changes: 53 additions & 0 deletions rules/goldstein/README.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test('goldstein: keyword: import', async ({compile}) => {
await compile('import');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test('goldstein: keyword: import', (t) => {
t.compile('import');
t.end();
});

30 changes: 30 additions & 0 deletions rules/goldstein/lib/convert-t-compile-to-compile/index.js
Original file line number Diff line number Diff line change
@@ -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)';
},
});
19 changes: 19 additions & 0 deletions rules/goldstein/lib/convert-t-compile-to-compile/index.spec.js
Original file line number Diff line number Diff line change
@@ -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();
});
5 changes: 5 additions & 0 deletions rules/goldstein/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import * as convertTCompileToCompile from './convert-t-compile-to-compile/index.js';

export const rules = {
'convert-t-compile-to-compile': convertTCompileToCompile,
};
52 changes: 52 additions & 0 deletions rules/goldstein/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@putout/plugin-goldstein",
"version": "1.0.0",
"type": "module",
"author": "coderaiser <[email protected]> (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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test('goldstein: keyword: import', async ({compile}) => {
await compile('import');
t.end();
});
5 changes: 5 additions & 0 deletions rules/goldstein/test/fixture/convert-t-compile-to-compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test('goldstein: keyword: import', (t) => {
t.compile('import');
t.end();
});

14 changes: 14 additions & 0 deletions rules/goldstein/test/goldstein.js
Original file line number Diff line number Diff line change
@@ -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();
});

0 comments on commit 86c5230

Please sign in to comment.