Skip to content

Commit

Permalink
Update tsconfig.json
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Feb 7, 2023
1 parent 54cccb0 commit 3c377f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
26 changes: 14 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* @typedef {import('unist').Point} Point
* @typedef {import('vfile').VFile} VFile
*
* @typedef {Pick<Point, 'line'|'column'>} PositionalPoint
* @typedef {Required<Point>} FullPoint
* @typedef {NonNullable<Point['offset']>} Offset
* @typedef Point
* @property {number | undefined} line
* @property {number | undefined} column
* @property {number | undefined} [offset]
*/

/**
Expand All @@ -31,8 +31,8 @@ export function location(file) {
* Returns a point with `undefined` values when given invalid or out of bounds
* input.
*
* @param {Offset} offset
* @returns {FullPoint}
* @param {number} offset
* @returns {Point}
*/
function toPoint(offset) {
let index = -1
Expand All @@ -56,14 +56,12 @@ export function location(file) {
* Get the `offset` for a line and column-based `point` in the bound indices.
* Returns `-1` when given invalid or out of bounds input.
*
* @param {PositionalPoint} point
* @returns {Offset}
* @param {Point} point
* @returns {number}
*/
function toOffset(point) {
const line = point && point.line
const column = point && point.column
/** @type {number} */
let offset

if (
typeof line === 'number' &&
Expand All @@ -72,9 +70,13 @@ export function location(file) {
!Number.isNaN(column) &&
line - 1 in indices
) {
offset = (indices[line - 2] || 0) + column - 1 || 0
const offset = (indices[line - 2] || 0) + column - 1 || 0

if (offset > -1 && offset < indices[indices.length - 1]) {
return offset
}
}

return offset > -1 && offset < indices[indices.length - 1] ? offset : -1
return -1
}
}
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
Expand Down
18 changes: 10 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"include": ["*.js"],
"include": ["**/*.js"],
"exclude": ["coverage/", "node_modules/"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2020"],
"module": "node16",
"newLine": "lf",
"skipLibCheck": true,
"strict": true,
"target": "es2020"
}
}

0 comments on commit 3c377f1

Please sign in to comment.