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
Update VFile #19583
Merged
Merged
Update VFile #19583
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
122500f
Add VFile
Rokt33r 7eb5ba8
Fix typings for vfile by the guide of the author
Rokt33r 08c0fcf
Add more type of argument for position
Rokt33r 61cf931
Add more option for position arguments
Rokt33r 34b2133
Exploit generics to assert typings of custom data
Rokt33r ec9ef2c
Add failure scenario
Rokt33r 65698d1
Update comment
Rokt33r 0f323ca
Use never because it always throw an error
Rokt33r 798233d
Accept `Position` with extra properties
Rokt33r 3dd0a90
Fix rollback Node
Rokt33r f161e0e
Fix wrong variable name
Rokt33r fc6a0fb
Fix conflicts
Rokt33r 9a6f7da
Fix a test case by the description
Rokt33r 37207e1
Delete generic `D` which was represented as `data` property.
Rokt33r e59a1c2
Pass generic directly if it instantiate without any other options exc…
Rokt33r 34bc9e6
Remove unused generic N
Rokt33r File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Type definitions for vfile 2.2 | ||
// Project: https://github.com/vfile/vfile#readme | ||
// Definitions by: Junyoung Choi <https://github.com/rokt33r> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
/// <reference types="node" /> | ||
|
||
declare namespace vfile { | ||
type Contents = string | Buffer; | ||
|
||
interface Point { | ||
line: number; | ||
column: number; | ||
} | ||
|
||
interface Position { | ||
start: Point; | ||
end: Point; | ||
} | ||
|
||
interface VFileParams { | ||
contents?: Contents; | ||
path?: string; | ||
basename?: string; | ||
stem?: string; | ||
extname?: string; | ||
dirname?: string; | ||
cwd?: string; | ||
} | ||
|
||
interface VFileError { | ||
ruleId: string | null; | ||
name: string; | ||
file: string; | ||
reason: string; | ||
line: number | null; | ||
column: number | null; | ||
location: Position; | ||
source: string | null; | ||
fatal?: boolean | null; | ||
} | ||
|
||
type Message = (reason: string, position?: Point | Position, ruleId?: string) => VFileError; | ||
|
||
type Fail = (reason?: string, position?: Point | Position, ruleId?: string) => void; | ||
|
||
type Info = (reason?: string, position?: Point | Position, ruleId?: string) => void; | ||
|
||
type ToString = (encoding?: BufferEncoding) => string; | ||
|
||
interface VFile { | ||
(input?: Contents | VFile | VFileParams): VFile; | ||
message: Message; | ||
fail: Fail; | ||
info: Info; | ||
history: string[]; | ||
data: {}; | ||
messages: VFileError[]; | ||
contents: Contents; | ||
path?: string; | ||
dirname?: string; | ||
basename?: string; | ||
stem?: string; | ||
extname?: string; | ||
cwd: string; | ||
toString: ToString; | ||
} | ||
} | ||
|
||
declare const vfile: vfile.VFile; | ||
|
||
export = vfile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2017", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"vfile-tests.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import vfile = require("vfile"); | ||
|
||
const file = vfile({path: '~/example.txt', contents: 'Alpha *braavo* charlie.'}); | ||
|
||
file.path; // => '~/example.txt' | ||
file.dirname; // => '~' | ||
|
||
file.extname = '.md'; | ||
|
||
file.basename; // => 'example.md' | ||
|
||
file.basename = 'index.text'; | ||
|
||
file.history; // => ['~/example.txt', '~/example.md', '~/index.text'] | ||
|
||
file.message('`braavo` is misspelt; did you mean `bravo`?', {line: 1, column: 8}); | ||
|
||
console.log(file.messages); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wooorm I've also found, position can be
Point
orPosition
. Do I understand right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Or a
Node
!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!