Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jun 11, 2022
1 parent db4d87b commit d5b9154
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
20 changes: 10 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* @typedef {import('vfile-message').VFileMessage} VFileMessage
*/

var severities = {true: 2, false: 1, null: 0, undefined: 0}
const severities = {true: 2, false: 1, null: 0, undefined: 0}

/**
* @template {VFile} F
* @param {F} file
* @returns {F}
* @template {VFile} File
* @param {File} file
* @returns {File}
*/
export function sort(file) {
file.messages.sort(comparator)
Expand All @@ -35,19 +35,19 @@ function comparator(a, b) {
/**
* @param {VFileMessage} a
* @param {VFileMessage} b
* @param {string} property
* @param {string} field
* @returns {number}
*/
function check(a, b, property) {
return (a[property] || 0) - (b[property] || 0)
function check(a, b, field) {
return (a[field] || 0) - (b[field] || 0)
}

/**
* @param {VFileMessage} a
* @param {VFileMessage} b
* @param {string} property
* @param {string} field
* @returns {number}
*/
function compare(a, b, property) {
return String(a[property] || '').localeCompare(b[property] || '')
function compare(a, b, field) {
return String(a[field] || '').localeCompare(b[field] || '')
}
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"rules": {
"no-var": "off",
"prefer-arrow-callback": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Expand Down
12 changes: 6 additions & 6 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ import {VFile} from 'vfile'
import {sort} from './index.js'

test('sort()', function (t) {
var file = new VFile()
let file = new VFile()

// @ts-ignore runtime.
// @ts-expect-error runtime.
file.message('Hotel', {column: 0})
file.message('Foxtrot')
// @ts-ignore runtime.
// @ts-expect-error runtime.
file.message('Alpha', {line: 3})
file.message('Bravo', {line: 3, column: 1})
file.message('Charlie', {line: 3, column: 2})
file.message('Delta', {line: 0, column: 1})
// @ts-ignore runtime.
// @ts-expect-error runtime.
file.message('Echo', {column: 1})
// @ts-ignore runtime.
// @ts-expect-error runtime.
file.message('Golf', {line: 0})
// @ts-ignore runtime.
// @ts-expect-error runtime.
file.message('Golf', {line: 0})

t.deepEqual(sort(file).messages.map(String), [
Expand Down

0 comments on commit d5b9154

Please sign in to comment.