forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add definition for prettier-linter-helpers v1.0 (DefinitelyType…
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
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,34 @@ | ||
// Type definitions for prettier-linter-helpers 1.0 | ||
// Project: https://github.com/prettier/prettier-linter-helpers | ||
// Definitions by: JounQin <https://github.com/JounQin> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
/** | ||
* Converts invisible characters to a commonly recognizable visible form. | ||
* @param str - The string with invisibles to convert. | ||
* @returns The converted string. | ||
*/ | ||
export function showInvisibles(str: string): string; | ||
|
||
export interface GenerateDifferences { | ||
/** | ||
* Generate results for differences between source code and formatted version. | ||
* | ||
* @param source - The original source. | ||
* @param prettierSource - The Prettier formatted source. | ||
* @returns An array containing { operation, offset, insertText, deleteText } | ||
*/ | ||
(source: string, prettierSource: string): Difference[]; | ||
INSERT: 'insert'; | ||
DELETE: 'delete'; | ||
REPLACE: 'replace'; | ||
} | ||
|
||
export const generateDifferences: GenerateDifferences; | ||
|
||
export interface Difference { | ||
operation: 'insert' | 'delete' | 'replace'; | ||
offset: number; | ||
insertText?: string; | ||
deleteText?: string; | ||
} |
27 changes: 27 additions & 0 deletions
27
types/prettier-linter-helpers/prettier-linter-helpers-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,27 @@ | ||
import { generateDifferences, showInvisibles } from 'prettier-linter-helpers'; | ||
|
||
declare function log(...args: Array<string | number>): void; | ||
|
||
showInvisibles(' some string '); | ||
|
||
generateDifferences('abc', 'def').forEach(difference => { | ||
const { operation, offset, deleteText = '', insertText = '' } = difference; | ||
|
||
switch (operation) { | ||
case 'delete': | ||
log('delete', offset, deleteText); | ||
break; | ||
case 'insert': | ||
log('insert', offset, insertText); | ||
break; | ||
case 'replace': | ||
log('replace', offset, insertText, deleteText); | ||
break; | ||
default: | ||
throw new Error(`Unexpected operation: '${operation}'`); | ||
} | ||
}); | ||
|
||
generateDifferences.INSERT; | ||
generateDifferences.DELETE; | ||
generateDifferences.REPLACE; |
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", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"prettier-linter-helpers-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" } |