Skip to content

Commit 8f51e2a

Browse files
committed
chore(deps): update deps and format style
1 parent 7d23982 commit 8f51e2a

File tree

5 files changed

+2863
-1443
lines changed

5 files changed

+2863
-1443
lines changed

package.json

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,37 @@
2525
"build": "textlint-scripts build",
2626
"watch": "textlint-scripts build --watch",
2727
"prepublish": "npm run --if-present build",
28-
"test": "textlint-scripts test"
28+
"test": "textlint-scripts test",
29+
"prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\""
2930
},
3031
"keywords": [
3132
"textlint",
3233
"textlintrule"
3334
],
3435
"devDependencies": {
35-
"textlint-scripts": "^2.1.0"
36+
"husky": "^4.2.5",
37+
"lint-staged": "^10.2.0",
38+
"prettier": "^2.0.5",
39+
"textlint-scripts": "^3.0.0"
3640
},
3741
"dependencies": {
3842
"array-includes": "^3.0.3",
3943
"is-capitalized": "^1.0.0"
44+
},
45+
"prettier": {
46+
"singleQuote": false,
47+
"printWidth": 120,
48+
"tabWidth": 4
49+
},
50+
"husky": {
51+
"hooks": {
52+
"pre-commit": "lint-staged"
53+
}
54+
},
55+
"lint-staged": {
56+
"*.{js,jsx,ts,tsx,css}": [
57+
"prettier --write",
58+
"git add"
59+
]
4060
}
41-
}
61+
}
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
// LICENSE : MIT
22
"use strict";
3-
const isCapitalized = require('is-capitalized');
4-
const includes = require('array-includes');
3+
const isCapitalized = require("is-capitalized");
4+
const includes = require("array-includes");
55
import AcronymCreator from "./AcronymCreator";
6-
import {isAllCapitals, expandWordsToAcronym} from "./word-utils";
6+
import { isAllCapitals, expandWordsToAcronym } from "./word-utils";
77
const defaultOptions = {
88
min_acronym_len: 3,
99
max_acronym_len: 5,
1010
ignore_acronyms: [],
11-
acronymJoiningWords: [
12-
"of",
13-
"the",
14-
"for",
15-
"in",
16-
"and",
17-
"or",
18-
"&"
19-
]
11+
acronymJoiningWords: ["of", "the", "for", "in", "and", "or", "&"],
2012
};
2113

2214
/*
@@ -32,7 +24,7 @@ module.exports = function (context, options = {}) {
3224
const maxAcronymLength = options.max_acronym_len || defaultOptions.max_acronym_len;
3325
const ignoreAcronymList = options.ignore_acronyms || defaultOptions.ignore_acronyms;
3426
const acronymJoiningWords = options.acronymJoiningWords || defaultOptions.acronymJoiningWords;
35-
const {Syntax, RuleError, report, getSource} = context;
27+
const { Syntax, RuleError, report, getSource } = context;
3628
// pickup acronyms
3729
const acronymList = [];
3830
// original words in document
@@ -46,13 +38,13 @@ module.exports = function (context, options = {}) {
4638
return true;
4739
};
4840
return {
49-
[Syntax.Str](node){
41+
[Syntax.Str](node) {
5042
const text = getSource(node);
5143
const words = text.split(/\b/);
5244
const acronymCreator = new AcronymCreator();
53-
words.forEach(word => {
45+
words.forEach((word) => {
5446
if (word.trim().length === 0) {
55-
return
47+
return;
5648
}
5749
if (isAllCapitals(word)) {
5850
// collect Acronym
@@ -64,11 +56,13 @@ module.exports = function (context, options = {}) {
6456
// Add temporarySequence
6557
// => add temp [Aword, Bword, Cword] = ABC
6658
acronymCreator.addWord(word);
67-
} else if (!includes(acronymJoiningWords, word) // ignore of and...
68-
&& acronymCreator.canExtractAcronym()) {
59+
} else if (
60+
!includes(acronymJoiningWords, word) && // ignore of and...
61+
acronymCreator.canExtractAcronym()
62+
) {
6963
// Create Acronym
7064
var acronyms = acronymCreator.extractAcronym();
71-
acronyms.forEach(acronym => {
65+
acronyms.forEach((acronym) => {
7266
if (isWordSatisfy(acronym)) {
7367
expandedAcronymList.push(acronym);
7468
}
@@ -78,20 +72,23 @@ module.exports = function (context, options = {}) {
7872
if (acronymCreator.canExtractAcronym()) {
7973
// Create Acronym
8074
var acronyms = acronymCreator.extractAcronym();
81-
acronyms.forEach(acronym => {
75+
acronyms.forEach((acronym) => {
8276
if (isWordSatisfy(acronym)) {
8377
expandedAcronymList.push(acronym);
8478
}
8579
});
8680
}
8781
},
88-
[Syntax.Document + ":exit"](node){
89-
acronymList.forEach(acronym => {
82+
[Syntax.Document + ":exit"](node) {
83+
acronymList.forEach((acronym) => {
9084
// not found acronym in document
9185
if (!includes(expandedAcronymList, acronym)) {
92-
report(node, new RuleError(`"${acronym}" is unexpanded acronym. What does "${acronym}" stand for?`));
86+
report(
87+
node,
88+
new RuleError(`"${acronym}" is unexpanded acronym. What does "${acronym}" stand for?`)
89+
);
9390
}
9491
});
95-
}
96-
}
97-
}
92+
},
93+
};
94+
};

src/word-utils.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,27 @@ export function expandOneWordToAcronym(CapitalWord) {
2626
/*
2727
* create Acronym from words.
2828
* @param {string[]} words
29-
* @returns (1)string if only one word (2) array if multiple words
29+
* @returns (1)string if only one word (2) array if multiple words
3030
*/
3131
export function expandWordsToAcronym(words) {
3232
//XMLHttpRequest -> XHR
3333
if (words.length === 1) {
3434
return [expandOneWordToAcronym(words[0])];
35-
}
36-
else{
35+
} else {
3736
const result = [];
3837
//In American Broadcast Company -> ["C", "BC", "ABC", "IABC"]
3938
words.reverse().reduce((acronym, word, i) => {
40-
acronym.unshift(word.charAt(0))
41-
result.push(acronym.join(""))
39+
acronym.unshift(word.charAt(0));
40+
result.push(acronym.join(""));
4241
return acronym;
4342
}, []);
4443

4544
//In American Broadcast Company -> ["I", "IA", "IAB", "IABC"]
4645
words.reverse().reduce((acronym, word, i) => {
4746
acronym.push(word.charAt(0));
48-
result.push(acronym.join(""))
47+
result.push(acronym.join(""));
4948
return acronym;
5049
}, []);
5150
return result;
5251
}
53-
}
52+
}

test/textlint-rule-unexpanded-acronym-test.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,41 @@ NAACP: (N double A C P) National Association for the Advancement of Colored Peop
2525
NCAA: (N C double A or N C two A or N C A A) National Collegiate Athletic Association
2626
In the Amazon Web Service, it can be short as AWS.
2727
Enter the Amazon Resource Names(ARN) for the Lambda you created in the setting
28-
`
28+
`,
2929
},
3030
// options
3131
{
3232
text: "OSS",
3333
options: {
34-
ignore_acronyms: ["OSS"]
35-
}
34+
ignore_acronyms: ["OSS"],
35+
},
3636
},
3737
{
3838
text: "GREEEEEEN",
3939
options: {
40-
max_acronym_len: 5
41-
}
42-
}
40+
max_acronym_len: 5,
41+
},
42+
},
4343
],
4444
invalid: [
4545
{
4646
text: "WHO",
47-
errors: [
48-
{message: `"WHO" is unexpanded acronym. What does "WHO" stand for?`}
49-
]
50-
}, {
47+
errors: [{ message: `"WHO" is unexpanded acronym. What does "WHO" stand for?` }],
48+
},
49+
{
5150
text: `When it comes to the Subject Of Cake (the sweet and delicious baked delicacy), one should
5251
always remember (or at least consider).this foodstuff's effect on one's ever-expanding waistline.
5352
5453
Now we know what SOC stands for but there is no mention of TTP.`,
55-
errors: [
56-
{message: `"TTP" is unexpanded acronym. What does "TTP" stand for?`}
57-
]
58-
}, {
54+
errors: [{ message: `"TTP" is unexpanded acronym. What does "TTP" stand for?` }],
55+
},
56+
{
5957
text: "use XHR, but we don't know what XHR.",
60-
errors: [
61-
{message: `"XHR" is unexpanded acronym. What does "XHR" stand for?`}
62-
]
63-
}, {
58+
errors: [{ message: `"XHR" is unexpanded acronym. What does "XHR" stand for?` }],
59+
},
60+
{
6461
text: "HELLO is just a capitalized word.",
65-
errors: [
66-
{message: `"HELLO" is unexpanded acronym. What does "HELLO" stand for?`}
67-
]
68-
}
69-
]
62+
errors: [{ message: `"HELLO" is unexpanded acronym. What does "HELLO" stand for?` }],
63+
},
64+
],
7065
});

0 commit comments

Comments
 (0)