Skip to content

Commit

Permalink
Change to disallow binary comparison by default
Browse files Browse the repository at this point in the history
This also renames the `noBinary` (used to be on) option to `binary` (now off).
  • Loading branch information
wooorm committed Sep 12, 2023
1 parent 5285424 commit 508c610
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 37 deletions.
12 changes: 6 additions & 6 deletions lib/create-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
* @typedef Options
* Configuration.
* @property {ReadonlyArray<string> | null | undefined} [ignore]
* phrases *not* to warn about (optional).
* @property {boolean | null | undefined} [noBinary=false]
* Whether to warn for “he or she” and similar (default: `false`).
* Phrases *not* to warn about (optional).
* @property {boolean | null | undefined} [binary=false]
* Whether to allow “he or she”, “garbagemen and garbagewomen”, and similar
* (default: `false`).
*/

import {ok as assert} from 'devlop'
Expand Down Expand Up @@ -81,7 +82,7 @@ export function createPlugin(patterns, lang) {
return function (options) {
const settings = options || emptyOptions
const ignore = settings.ignore || emptyList
const noBinary = settings.noBinary || false
const binary = settings.binary || false
/** @type {Array<string>} */
const noNormalize = []
/** @type {Array<string>} */
Expand Down Expand Up @@ -121,8 +122,7 @@ export function createPlugin(patterns, lang) {
for (const [id, matches] of matchesById.entries()) {
const pattern = byId.get(id)
assert(pattern)
const kind =
pattern.type === 'or' && noBinary ? 'basic' : pattern.type
const kind = !binary && pattern.type === 'or' ? 'basic' : pattern.type
handlers[kind](matches, pattern, file)
}

Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ Configuration (TypeScript type).

* `ignore` (`Array<string>`, optional)
— phrases *not* to warn about
* `noBinary` (`boolean`, default: `false`)
— whether to warn for “he or she” and similar
* `binary` (`boolean`, default: `false`)
— whether to allow “he or she”, “garbagemen and garbagewomen”, and similar

## Messages

Expand Down
10 changes: 5 additions & 5 deletions rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ potentially more considerate alternatives.
###### Or

**Or** patterns highlight possible inconsiderate terms unless every category is
present.
This is used for gendered work titles and the like, where `garbageman and
garbagewoman` is considered OK, and so is `his or her bike`.
These patterns can be turned into **basic** patterns by passing `noBinary:
true`, thus suggesting two alternatives for `him or her`.
present and `binary` is on.
This is used for gendered work titles such as `garbageman and garbagewoman`, or
stuff like `his or her bike`.
Normally these are treated as basic patterns, but you can pass `binary: true`
to allow them.

**Or** patterns can be joined by `and`, `or`, or a slash (`/`).

Expand Down
58 changes: 34 additions & 24 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,47 +90,57 @@ test('retext-equality', async function (t) {
])
})

await t.test('should ignore `/` comparison', async function () {
assert.deepEqual(await process('Her/his bicycle.'), [])
await t.test('should ignore `/` comparison w/ `binary`', async function () {
assert.deepEqual(await process('Her/his bicycle.', {binary: true}), [])
})

await t.test('should ignore `and` comparison', async function () {
assert.deepEqual(await process('Her and his bicycle.'), [])
await t.test('should warn for `/` comparison', async function () {
assert.deepEqual(await process('Her/his bicycle.'), [
'1:1-1:4: Unexpected potentially insensitive use of `Her`, when referring to a person, in somes cases `Their`, `Theirs`, `Them` may be better',
'1:5-1:8: Unexpected potentially insensitive use of `his`, when referring to a person, in somes cases `their`, `theirs`, `them` may be better'
])
})

await t.test('should ignore `and` comparison w/ `binary`', async function () {
assert.deepEqual(await process('Her and his bicycle.', {binary: true}), [])
})

await t.test('should ignore `or` comparison w/ `binary`', async function () {
assert.deepEqual(await process('Her or his bicycle.', {binary: true}), [])
})

await t.test(
'should not ignore `and` comparison when `noBinary: true`',
'should warn for binary `and` comparison by default',
async function () {
assert.deepEqual(
await process('Her and his bicycle.', {noBinary: true}),
[
'1:1-1:4: Unexpected potentially insensitive use of `Her`, when referring to a person, in somes cases `Their`, `Theirs`, `Them` may be better',
'1:9-1:12: Unexpected potentially insensitive use of `his`, when referring to a person, in somes cases `their`, `theirs`, `them` may be better'
]
)
assert.deepEqual(await process('Her and his bicycle.'), [
'1:1-1:4: Unexpected potentially insensitive use of `Her`, when referring to a person, in somes cases `Their`, `Theirs`, `Them` may be better',
'1:9-1:12: Unexpected potentially insensitive use of `his`, when referring to a person, in somes cases `their`, `theirs`, `them` may be better'
])
}
)

await t.test('should ignore `or` comparison', async function () {
assert.deepEqual(await process('Her or his bicycle.'), [])
})

await t.test(
'should not ignore `or` comparison when `noBinary: true`',
'should warn for binary `or` comparison with `binary: false` (default)',
async function () {
assert.deepEqual(await process('Her or his bicycle.', {noBinary: true}), [
assert.deepEqual(await process('Her or his bicycle.', {binary: false}), [
'1:1-1:4: Unexpected potentially insensitive use of `Her`, when referring to a person, in somes cases `Their`, `Theirs`, `Them` may be better',
'1:8-1:11: Unexpected potentially insensitive use of `his`, when referring to a person, in somes cases `their`, `theirs`, `them` may be better'
])
}
)

await t.test('should not ignore other close words', async function () {
assert.deepEqual(await process('Her bike, his bicycle.'), [
'1:1-1:4: Unexpected potentially insensitive use of `Her`, when referring to a person, in somes cases `Their`, `Theirs`, `Them` may be better',
'1:11-1:14: Unexpected potentially insensitive use of `his`, when referring to a person, in somes cases `their`, `theirs`, `them` may be better'
])
})
await t.test(
'should not ignore other close words w/ `binary`',
async function () {
assert.deepEqual(
await process('Her bike, his bicycle.', {binary: true}),
[
'1:1-1:4: Unexpected potentially insensitive use of `Her`, when referring to a person, in somes cases `Their`, `Theirs`, `Them` may be better',
'1:11-1:14: Unexpected potentially insensitive use of `his`, when referring to a person, in somes cases `their`, `theirs`, `them` may be better'
]
)
}
)

await t.test('should support `bipolar` (without dash)', async function () {
assert.deepEqual(await process('Two bipolar magnets.'), [
Expand Down

0 comments on commit 508c610

Please sign in to comment.