Skip to content

Commit

Permalink
feat: Support year abbreviations (#30)
Browse files Browse the repository at this point in the history
Support using the correct apostrophe style (`’`) for two-digit year abbreviations (e.g. `Summer of ’69`)

Ensures that other similar situations involving numbers and apostrophes do not get inadvertently changed.

Fixes #13
  • Loading branch information
groenroos authored Jan 25, 2024
1 parent 5469a8b commit 2187663
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const evilApostropheRegExp = /\w+['](?:\w['])?\w*/g;
const evilApostropheRegExp = /(?:(?<=\s)|[^\d\W])+['](?:\w['])?\w*/g;
const evilApostrophe = /[']/g;
const goodApostrophe = '’';

Expand Down
23 changes: 22 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const TextLintTester = require('textlint-tester');
const TextLintTester = require('textlint-tester').default;
const rule = require('./index');

const tester = new TextLintTester();
Expand All @@ -8,6 +8,9 @@ tester.run('apostrophe', rule, {
'I’m looking forward',
'rock’n’roll',
'my sisters’ friends’ investments',
'Summer of ’69',
'Personal best: 00\'03"48',
'Latitude: 49° 53\' 08"',
],
invalid: [
{
Expand Down Expand Up @@ -44,5 +47,23 @@ tester.run('apostrophe', rule, {
},
],
},
{
text: "Summer of '69",
output: 'Summer of ’69',
errors: [
{
message: "Incorrect usage of an apostrophe: “'69”, use “’69” instead",
},
],
},
{
text: 'Summer of ‘69',
output: 'Summer of ’69',
errors: [
{
message: 'Incorrect usage of an apostrophe: “‘69”, use “’69” instead',
},
],
},
],
});

0 comments on commit 2187663

Please sign in to comment.