Skip to content

Commit

Permalink
Merge pull request #21034 from Yoast/255-inclusive-language-tech-debt…
Browse files Browse the repository at this point in the history
…-flip-the-behavior-of-the-isprecededbyexception-function

255 inclusive language tech debt flip the behavior of the isprecededbyexception function
  • Loading branch information
hannaw93 committed Jan 16, 2024
2 parents 2d0501d + ad743a0 commit e9eb51a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ xdescribe( "Test isFollowedByException", () => {
it( "returns the right value when term is preceded by an exception", () => {
const words = "this is a sentence".split( " " );
const exceptions = [ "this" ];
const callback = isPrecededByException( words, exceptions );
const callback = isNotPrecededByException( words, exceptions );
const index = 1;

// eslint-disable-next-line callback-return
Expand All @@ -14,7 +14,7 @@ xdescribe( "Test isFollowedByException", () => {
it( "returns the right value when term is not preceded by an exception", () => {
const words = "that is a cat".split( " " );
const exceptions = [ "this" ];
const callback = isPrecededByException( words, exceptions );
const callback = isNotPrecededByException( words, exceptions );
const index = 1;

// eslint-disable-next-line callback-return
Expand All @@ -26,15 +26,15 @@ xdescribe( "Test isNotFollowedByException", () => {
it( "returns the right value when term is preceded by an exception", () => {
const words = "this is a sentence".split( " " );
const exceptions = [ "this" ];
const notCallback = isNotPrecededByException( words, exceptions );
const notCallback = isPrecededByException( words, exceptions );
const index = 1;

expect( notCallback( index ) ).toEqual( false );
} );
it( "returns the right value when term is not preceded by an exception", () => {
const words = "that is a cat".split( " " );
const exceptions = [ "this" ];
const notCallback = isNotPrecededByException( words, exceptions );
const notCallback = isPrecededByException( words, exceptions );
const index = 1;

expect( notCallback( index ) ).toEqual( true );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { potentiallyHarmful, potentiallyHarmfulUnless, harmfulNonInclusive } from "./feedbackStrings";
import { isPrecededByException } from "../helpers/isPrecededByException";
import { isNotPrecededByException } from "../helpers/isPrecededByException";
import { isNotFollowedByException } from "../helpers/isFollowedByException";
import { includesConsecutiveWords } from "../helpers/includesConsecutiveWords";
import { SCORES } from "./scores";
Expand Down Expand Up @@ -70,7 +70,7 @@ const ageAssessments = [
feedbackFormat: [ potentiallyHarmfulUnless, specificAgeGroup ].join( " " ),
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isPrecededByException( words, [ "high school", "college", "graduating", "juniors and" ] ) )
.filter( isNotPrecededByException( words, [ "high school", "college", "graduating", "juniors and" ] ) )
.filter( isNotFollowedByException( words, nonInclusivePhrase, [ "in high school", "in college", "who are graduating" ] ) );
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const disabilityAssessments = [
feedbackFormat: derogatory,
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isPrecededByException( words, [ "mentally" ] ) );
.filter( isNotPrecededByException( words, [ "mentally" ] ) );
},
},
{
Expand Down Expand Up @@ -346,7 +346,7 @@ const disabilityAssessments = [
feedbackFormat: potentiallyHarmful,
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isPrecededByException( words, [ "deaf and" ] ) );
.filter( isNotPrecededByException( words, [ "deaf and" ] ) );
},
},
{
Expand Down Expand Up @@ -414,7 +414,7 @@ const disabilityAssessments = [
// Target only when preceded by a form of "to be", the negation "not", and an optional intensifier (e.g. "is not so crazy about" ).
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isNotPrecededByException( words, formsOfToBeNotWithOptionalIntensifier ) );
.filter( isPrecededByException( words, formsOfToBeNotWithOptionalIntensifier ) );
},
},
{
Expand All @@ -426,7 +426,7 @@ const disabilityAssessments = [
// Target only when preceded by a form of "to be" and an optional intensifier (e.g. "am so crazy about")
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isNotPrecededByException( words, formsOfToBeWithOptionalIntensifier ) );
.filter( isPrecededByException( words, formsOfToBeWithOptionalIntensifier ) );
},
},
{
Expand All @@ -446,7 +446,7 @@ const disabilityAssessments = [
// Target only when preceded by a form of "to go" (e.g. 'going crazy').
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isNotPrecededByException( words, formsOfToGo ) );
.filter( isPrecededByException( words, formsOfToGo ) );
},
},
{
Expand All @@ -459,7 +459,7 @@ const disabilityAssessments = [
// Target only when preceded by a form of 'to drive' and an object pronoun (e.g. 'driving me crazy', 'drove everyone crazy').
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isNotPrecededByException( words, combinationsOfDriveAndObjectPronoun ) );
.filter( isPrecededByException( words, combinationsOfDriveAndObjectPronoun ) );
},
},
{
Expand All @@ -472,7 +472,7 @@ const disabilityAssessments = [
// Don't target when 'crazy' is part of a more specific phrase that we target.
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isPrecededByException( words, shouldNotPrecedeStandaloneCrazy ) )
.filter( isNotPrecededByException( words, shouldNotPrecedeStandaloneCrazy ) )
.filter( isNotFollowedByException( words, nonInclusivePhrase, shouldNotFollowStandaloneCrazy ) )
.filter( isNotFollowedAndPrecededByException( words, nonInclusivePhrase,
shouldNotPrecedeStandaloneCrazyWhenFollowedByAbout,
Expand Down Expand Up @@ -596,7 +596,7 @@ const disabilityAssessments = [
// Only target 'OCD' when preceded by a form of 'to be/to get' followed by an optional intensifier.
rule: ( words, inclusivePhrases ) => {
return includesConsecutiveWords( words, inclusivePhrases )
.filter( isNotPrecededByException( words, formsOfToBeAndToBeNotWithOptionalIntensifier ) );
.filter( isPrecededByException( words, formsOfToBeAndToBeNotWithOptionalIntensifier ) );
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
potentiallyHarmfulUnlessAnimalsObjects,
} from "./feedbackStrings";
import { includesConsecutiveWords } from "../helpers/includesConsecutiveWords";
import { isPrecededByException } from "../helpers/isPrecededByException";
import { isNotPrecededByException } from "../helpers/isPrecededByException";

const otherAssessments = [
{
Expand All @@ -28,7 +28,7 @@ const otherAssessments = [
feedbackFormat: potentiallyHarmful,
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isPrecededByException( words, [ "mentally", "behaviorally", "behaviourally" ] ) );
.filter( isNotPrecededByException( words, [ "mentally", "behaviorally", "behaviourally" ] ) );
},
},
{
Expand All @@ -41,7 +41,7 @@ const otherAssessments = [
caseSensitive: true,
rule: ( words, nonInclusivePhrase ) => {
return includesConsecutiveWords( words, nonInclusivePhrase )
.filter( isPrecededByException( words, [ "mentally", "behaviorally", "behaviourally" ] ) );
.filter( isNotPrecededByException( words, [ "mentally", "behaviorally", "behaviourally" ] ) );
},
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isFollowedByException } from "./isFollowedByException";
import { isNotPrecededByException } from "./isPrecededByException";
import { isPrecededByException } from "./isPrecededByException";


/**
Expand All @@ -19,7 +19,7 @@ import { isNotPrecededByException } from "./isPrecededByException";
export function isFollowedAndPrecededByException( words, nonInclusivePhrase, precedingExceptions, followingExceptions ) {
return ( index ) => {
return ( isFollowedByException( words, nonInclusivePhrase, followingExceptions )( index ) &&
isNotPrecededByException( words, precedingExceptions )( index ) );
isPrecededByException( words, precedingExceptions )( index ) );
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { includesWordsAtPosition } from "./includesWordsAtPosition";
*/
export function isPrecededByException( words, exceptions ) {
const splitExceptions = exceptions.map( exception => getWords( exception, false ) );
return index => ! splitExceptions.some( exception => {
return index => splitExceptions.some( exception => {
const startIndex = index - exception.length;
if ( startIndex >= 0 ) {
return includesWordsAtPosition( exception, startIndex, words );
Expand Down

0 comments on commit e9eb51a

Please sign in to comment.