Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Introduce CodeActions #316

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 36 additions & 36 deletions baselines/packages/mimir/test/formatters.spec.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,69 @@

The actual snapshot is saved in `formatters.spec.ts.snap`.

Generated by [AVA](https://ava.li).
Generated by [AVA](https://avajs.dev).

## JSON bom
## JSON empty

`[␊
{"severity":"error","message":"BOM","ruleName":"bom","start":{"position":0,"line":0,"character":0},"end":{"position":1,"line":0,"character":1},"fileName":"/dir/warnings.ts"},{"severity":"warning","message":"a","ruleName":"a","start":{"position":1,"line":0,"character":1},"end":{"position":2,"line":0,"character":2},"fileName":"/dir/warnings.ts"},{"severity":"warning","message":"b","ruleName":"a","start":{"position":3,"line":1,"character":0},"end":{"position":4,"line":1,"character":1},"fileName":"/dir/warnings.ts"},{"severity":"warning","message":"EOF","ruleName":"eof","start":{"position":4,"line":1,"character":1},"end":{"position":4,"line":1,"character":1},"fileName":"/dir/warnings.ts"}␊
]␊
`

## JSON empty
## JSON success

`[␊
]␊
`

## JSON fixable
## JSON fixed

`[␊
{"severity":"error","message":"debugger","ruleName":"no-debugger","start":{"position":0,"line":0,"character":0},"end":{"position":9,"line":0,"character":9},"fix":{"replacements":[{"start":0,"end":9,"text":""}]},"fileName":"/dir/fixableError.ts"}␊
]␊
`

## JSON fixed
## JSON fixable

`[␊
{"severity":"error","message":"debugger","ruleName":"no-debugger","start":{"position":0,"line":0,"character":0},"end":{"position":9,"line":0,"character":9},"fix":{"description":"auto fix","replacements":[{"start":0,"end":9,"text":""}]},"fileName":"/dir/fixableError.ts"}␊
]␊
`

## JSON mixed
## JSON warnings

`[␊
{"severity":"warning","message":"no foo","ruleName":"foo","start":{"position":0,"line":0,"character":0},"end":{"position":3,"line":0,"character":3},"fix":{"replacements":[{"start":0,"end":3,"text":""}]},"fileName":"/some/other/directory/b.ts"},{"severity":"error","message":"no bar","ruleName":"bar","start":{"position":6,"line":0,"character":6},"end":{"position":9,"line":0,"character":9},"fix":{"replacements":[{"start":6,"end":9,"text":"baz"}]},"fileName":"/some/other/directory/b.ts"},{"severity":"error","message":"no equals","ruleName":"equals","start":{"position":4,"line":0,"character":4},"end":{"position":5,"line":0,"character":5},"fileName":"/some/other/directory/b.ts"}␊
{"severity":"error","message":"missing trailing newline","ruleName":"trailing-newline","start":{"position":9,"line":0,"character":9},"end":{"position":9,"line":0,"character":9},"fix":{"replacements":[{"start":9,"end":9,"text":"\\n"}]},"fileName":"/my/project/a.ts"}␊
{"severity":"warning","message":"a","ruleName":"a","start":{"position":0,"line":0,"character":0},"end":{"position":0,"line":0,"character":0},"fileName":"/dir/warnings.ts"}␊
{"severity":"warning","message":"b","ruleName":"b","start":{"position":0,"line":0,"character":0},"end":{"position":0,"line":0,"character":0},"fileName":"C:/dir/warnings2.ts"}␊
]␊
`

## JSON success
## JSON mixed

`[␊
{"severity":"warning","message":"no foo","ruleName":"foo","start":{"position":0,"line":0,"character":0},"end":{"position":3,"line":0,"character":3},"fix":{"description":"auto fix","replacements":[{"start":0,"end":3,"text":""}]},"fileName":"/some/other/directory/b.ts"},{"severity":"error","message":"no bar","ruleName":"bar","start":{"position":6,"line":0,"character":6},"end":{"position":9,"line":0,"character":9},"fix":{"description":"auto fix","replacements":[{"start":6,"end":9,"text":"baz"}]},"fileName":"/some/other/directory/b.ts"},{"severity":"error","message":"no equals","codeActions":[{"description":"Convert assignment to comparison","replacements":[{"start":5,"end":5,"text":"=="}]},{"description":"Remove all the things","replacements":[{"start":1,"end":3,"text":""},{"start":7,"end":9,"text":""}]}],"ruleName":"equals","start":{"position":4,"line":0,"character":4},"end":{"position":5,"line":0,"character":5},"fileName":"/some/other/directory/b.ts"}␊
{"severity":"error","message":"missing trailing newline","ruleName":"trailing-newline","start":{"position":9,"line":0,"character":9},"end":{"position":9,"line":0,"character":9},"fix":{"description":"auto fix","replacements":[{"start":9,"end":9,"text":"\\n"}]},"fileName":"/my/project/a.ts"}␊
]␊
`

## JSON warnings
## JSON bom

`[␊
{"severity":"warning","message":"a","ruleName":"a","start":{"position":0,"line":0,"character":0},"end":{"position":0,"line":0,"character":0},"fileName":"/dir/warnings.ts"}␊
{"severity":"warning","message":"b","ruleName":"b","start":{"position":0,"line":0,"character":0},"end":{"position":0,"line":0,"character":0},"fileName":"C:/dir/warnings2.ts"}␊
{"severity":"error","message":"BOM","ruleName":"bom","start":{"position":0,"line":0,"character":0},"end":{"position":1,"line":0,"character":1},"fileName":"/dir/warnings.ts"},{"severity":"warning","message":"a","ruleName":"a","start":{"position":1,"line":0,"character":1},"end":{"position":2,"line":0,"character":2},"fileName":"/dir/warnings.ts"},{"severity":"warning","message":"b","ruleName":"a","start":{"position":3,"line":1,"character":0},"end":{"position":4,"line":1,"character":1},"fileName":"/dir/warnings.ts"},{"severity":"warning","message":"EOF","ruleName":"eof","start":{"position":4,"line":1,"character":1},"end":{"position":4,"line":1,"character":1},"fileName":"/dir/warnings.ts"}␊
]␊
`

## Stylish bom
## Stylish empty

`/dir/warnings.ts:1:1␊
ERROR 1:1 bom BOM␊
WARNING 1:1 a  a␊
WARNING 2:1 a  b␊
WARNING 2:2 eof EOF␊
✖ 1 error ⚠ 3 warnings␊
`
''

## Stylish empty
## Stylish success

''

## Stylish fixed

`Automatically fixed 1 finding.␊
`

## Stylish fixable

`/dir/fixableError.ts:1:1␊
Expand All @@ -76,9 +74,15 @@ Generated by [AVA](https://ava.li).
1 finding is potentially fixable with the '--fix' option.␊
`

## Stylish fixed
## Stylish warnings

`Automatically fixed 1 finding.␊
`/dir/warnings.ts:1:1␊
WARNING 1:1 a a␊
C:/dir/warnings2.ts:1:1␊
WARNING 1:1 b b␊
⚠ 2 warnings␊
`

## Stylish mixed
Expand All @@ -97,17 +101,13 @@ Generated by [AVA](https://ava.li).
3 findings are potentially fixable with the '--fix' option.␊
`

## Stylish success

''

## Stylish warnings
## Stylish bom

`/dir/warnings.ts:1:1␊
WARNING 1:1 a a␊
C:/dir/warnings2.ts:1:1
WARNING 1:1 b b␊
ERROR 1:1 bom BOM␊
WARNING 1:1 a  a
WARNING 2:1 a  b
WARNING 2:2 eof EOF␊
⚠ 2 warnings␊
✖ 1 error ⚠ 3 warnings␊
`
Binary file modified baselines/packages/mimir/test/formatters.spec.ts.snap
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
+++ generator-require-yield Convert to regular function.
@@ -2,9 +2,9 @@
function *foo() {
if (Boolean()) {
yield;
}
- (function *() {})
+ (function () {})
}
function *bar() {
(function *() {})
yield;

+++ generator-require-yield Convert to regular function.
@@ -5,9 +5,9 @@
}
(function *() {})
}
function *bar() {
- (function *() {})
+ (function () {})
yield;
}
function *baz() {
(function *() {

+++ generator-require-yield Convert to regular function.
@@ -8,9 +8,9 @@
function *bar() {
(function *() {})
yield;
}
- function *baz() {
+ function baz() {
(function *() {
yield;
})
}

+++ generator-require-yield Convert to regular function.
@@ -14,9 +14,9 @@
yield;
})
}
function *bas() {
- yield function *() {};
+ yield function () {};
}
});

const key = 'foo';

+++ generator-require-yield Convert to regular function.
@@ -21,9 +21,9 @@

const key = 'foo';
class Foo {
method() {}
- public *generator() {}
+ public generator() {}
private generatorProp = function *() {};
}
{
let obj = {

+++ generator-require-yield Convert to regular function.
@@ -22,9 +22,9 @@
const key = 'foo';
class Foo {
method() {}
public *generator() {}
- private generatorProp = function *() {};
+ private generatorProp = function () {};
}
{
let obj = {
*[key]() {},

+++ generator-require-yield Convert to regular function.
@@ -26,9 +26,9 @@
private generatorProp = function *() {};
}
{
let obj = {
- *[key]() {},
+ [key]() {},
*'name'() {},
*"method'name"() {},
};
}

+++ generator-require-yield Convert to regular function.
@@ -27,8 +27,8 @@
}
{
let obj = {
*[key]() {},
- *'name'() {},
+ 'name'() {},
*"method'name"() {},
};
}

+++ generator-require-yield Convert to regular function.
@@ -28,7 +28,7 @@
{
let obj = {
*[key]() {},
*'name'() {},
- *"method'name"() {},
+ "method'name"() {},
};
}
4 changes: 2 additions & 2 deletions baselines/packages/wotan/api/src/fix.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as ts from 'typescript';
import { Fix } from '@fimbul/ymir';
import { CodeAction } from '@fimbul/ymir';
export interface FixResult {
result: string;
fixed: number;
Expand All @@ -12,4 +12,4 @@ export interface FixResult {
* of this fix are not applied again.
* At least one fix will be applied.
*/
export declare function applyFixes(source: string, fixes: Fix[]): FixResult;
export declare function applyFixes(source: string, fixes: readonly CodeAction[]): FixResult;
50 changes: 25 additions & 25 deletions baselines/packages/wotan/test/baseline.spec.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,13 @@

The actual snapshot is saved in `baseline.spec.ts.snap`.

Generated by [AVA](https://ava.li).
Generated by [AVA](https://avajs.dev).

## createBaseline CRLF

`foo;␍␊
~~~~ [error rule: some message]␊
bar;␍␊
`

## createBaseline mixed
## createBaseline valid

`export {};␊
~~~~~~~~~~␊
~nil [warning rule: where is my squiggly tail]␊
~nil [error rule: where is my squiggly tail]␊
~~~~~~~~~␊
let foo = 'foo';␊
~~~~~~~~~~~~~~~~␊
~~~~ [warning other: two lines]␊
~~~~~~~~~~~~~~~~␊
let bar = foo;␊
~~~~~~~~~~~~~~ [error multiline: I am groot]␊
~~~~ [error another: other two lines]␊
`

## createBaseline multiline
Expand All @@ -37,22 +21,38 @@ Generated by [AVA](https://ava.li).
~~~~~~~~~~~~~~ [error multiline: I am groot]␊
`

## createBaseline no eofline

`let foo;␊
~nil [warning rule: where is my squiggly tail]`

## createBaseline valid
## createBaseline zero length

`export {};␊
~nil [warning rule: where is my squiggly tail]␊
let foo = 'foo';␊
let bar = foo;␊
`

## createBaseline zero length
## createBaseline mixed

`export {};␊
~~~~~~~~~~␊
~nil [warning rule: where is my squiggly tail]␊
~nil [error rule: where is my squiggly tail]␊
~~~~~~~~~␊
let foo = 'foo';␊
~~~~~~~~~~~~~~~~␊
~~~~ [warning other: two lines]␊
~~~~~~~~~~~~~~~~␊
let bar = foo;␊
~~~~~~~~~~~~~~ [error multiline: I am groot]␊
~~~~ [error another: other two lines]␊
`

## createBaseline no eofline

`let foo;␊
~nil [warning rule: where is my squiggly tail]`

## createBaseline CRLF

`foo;␍␊
~~~~ [error rule: some message]␊
bar;␍␊
`
Binary file modified baselines/packages/wotan/test/baseline.spec.ts.snap
Binary file not shown.
Loading