Skip to content

Commit 35491f5

Browse files
committed
chore: adjust code required by eslint/dep changes
1 parent 7dfcbe6 commit 35491f5

File tree

14 files changed

+93
-73
lines changed

14 files changed

+93
-73
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
}
1414
],
1515
"no-restricted-syntax": 0,
16-
"no-await-in-loop": "off"
16+
"no-await-in-loop": "off",
17+
"default-param-last": "off"
1718
},
1819
"overrides": [
1920
{

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/builtin-duckling/test/duckling.test.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,84 +33,98 @@ function getManager() {
3333
if (language.startsWith('en')) {
3434
switch (utterance) {
3535
case 'The email is [email protected], check it out':
36-
return resolve(
36+
resolve(
3737
JSON.parse(
3838
'[{"body":"[email protected]","start":13,"value":{"value":"[email protected]"},"end":26,"dim":"email","latent":false}]'
3939
)
4040
);
41+
return;
4142
case 'The phone number is +1 (650) 123-4567':
42-
return resolve(
43+
resolve(
4344
JSON.parse(
4445
'[{"body":"+1 (650) 123-4567","start":20,"value":{"value":"(+1) 6501234567"},"end":37,"dim":"phone-number","latent":false}]'
4546
)
4647
);
48+
return;
4749
case 'The url is https://subdomain.domain.com/something':
48-
return resolve(
50+
resolve(
4951
JSON.parse(
5052
'[{"body":"https://subdomain.domain.com/something","start":11,"value":{"domain":"subdomain.domain.com","value":"https://subdomain.domain.com/something"},"end":49,"dim":"url","latent":false}]'
5153
)
5254
);
55+
return;
5356
case 'The number is one hundred and twelve':
54-
return resolve(
57+
resolve(
5558
JSON.parse(
5659
'[{"body":"one hundred and twelve","start":14,"value":{"value":112,"type":"value"},"end":36,"dim":"number","latent":false}]'
5760
)
5861
);
62+
return;
5963
case 'The number is one hundred and twelve dot 5':
60-
return resolve(
64+
resolve(
6165
JSON.parse(
6266
'[{"body":"one hundred and twelve dot 5","start":14,"value":{"value":112.5,"type":"value"},"end":42,"dim":"number","latent":false}]'
6367
)
6468
);
69+
return;
6570
case 'There are 347kms':
66-
return resolve(
71+
resolve(
6772
JSON.parse(
6873
'[{"body":"347kms","start":10,"value":{"value":347,"type":"value","unit":"kilometre"},"end":16,"dim":"distance","latent":false}]'
6974
)
7075
);
76+
return;
7177
case 'Three cups of sugar':
72-
return resolve(
78+
resolve(
7379
JSON.parse(
7480
'[{"body":"Three cups of sugar","start":0,"value":{"value":3,"type":"value","product":"sugar","unit":"cup"},"end":19,"dim":"quantity","latent":false}]'
7581
)
7682
);
83+
return;
7784
case '80F':
78-
return resolve(
85+
resolve(
7986
JSON.parse(
8087
'[{"body":"80F","start":0,"value":{"value":80,"type":"value","unit":"fahrenheit"},"end":3,"dim":"temperature","latent":false}]'
8188
)
8289
);
90+
return;
8391
case '4 gallons':
84-
return resolve(
92+
resolve(
8593
JSON.parse(
8694
'[{"body":"4 gallons","start":0,"value":{"value":4,"type":"value","unit":"gallon"},"end":9,"dim":"volume","latent":false}]'
8795
)
8896
);
97+
return;
8998
case '42€':
90-
return resolve(
99+
resolve(
91100
JSON.parse(
92101
'[{"body":"42€","start":0,"value":{"value":42,"type":"value","unit":"EUR"},"end":3,"dim":"amount-of-money","latent":false}]'
93102
)
94103
);
104+
return;
95105
case '3 mins':
96-
return resolve(
106+
resolve(
97107
JSON.parse(
98108
'[{"body":"3 mins","start":0,"value":{"value":3,"type":"value","minute":3,"unit":"minute","normalized":{"value":180,"unit":"second"}},"end":6,"dim":"duration","latent":false}]'
99109
)
100110
);
111+
return;
101112
case '12/12/2019 at 9am':
102-
return resolve(
113+
resolve(
103114
JSON.parse(
104115
'[{"body":"12/12/2019 at 9am","start":0,"value":{"values":[{"value":"2019-12-12T09:00:00.000+00:00","grain":"hour","type":"value"}],"value":"2019-12-12T09:00:00.000+00:00","grain":"hour","type":"value"},"end":17,"dim":"time","latent":false}]'
105116
)
106117
);
118+
return;
107119
case 'raise exception':
108-
return reject(new Error('Exception!'));
120+
reject(new Error('Exception!'));
121+
return;
109122
default:
110-
return resolve({});
123+
resolve({});
124+
return;
111125
}
112126
}
113-
return resolve({});
127+
resolve({});
114128
});
115129
return manager;
116130
}

packages/core-loader/src/container-bootstrap.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24-
const fs = require("fs");
25-
const path = require("path");
24+
const fs = require('fs');
25+
const path = require('path');
2626
const {
2727
ArrToObj,
2828
Container,
@@ -34,26 +34,26 @@ const {
3434
Timer,
3535
logger,
3636
MemoryStorage,
37-
} = require("@nlpjs/core");
38-
const { fs: requestfs, request } = require("@nlpjs/request");
39-
const pluginInformation = require("./plugin-information.json");
37+
} = require('@nlpjs/core');
38+
const { fs: requestfs, request } = require('@nlpjs/request');
39+
const pluginInformation = require('./plugin-information.json');
4040
const {
4141
listFilesAbsolute,
4242
getAbsolutePath,
4343
loadEnv,
4444
loadEnvFromJson,
45-
} = require("./helper");
45+
} = require('./helper');
4646

47-
const defaultPathConfiguration = "./conf.json";
48-
const defaultPathPipeline = "./pipelines.md";
49-
const defaultPathPlugins = "./plugins";
47+
const defaultPathConfiguration = './conf.json';
48+
const defaultPathPipeline = './pipelines.md';
49+
const defaultPathPlugins = './plugins';
5050

5151
function loadPipelinesStr(instance, pipelines) {
5252
instance.loadPipelinesFromString(pipelines);
5353
}
5454

5555
function loadPipelinesFromFile(instance, fileName) {
56-
const str = fs.readFileSync(fileName, "utf8");
56+
const str = fs.readFileSync(fileName, 'utf8');
5757
instance.loadPipelinesFromString(str);
5858
}
5959

@@ -65,7 +65,7 @@ function loadPipelines(instance, fileName) {
6565
} else if (fs.existsSync(fileName)) {
6666
if (fs.lstatSync(fileName).isDirectory()) {
6767
const files = listFilesAbsolute(fileName).filter((x) =>
68-
x.endsWith(".md"),
68+
x.endsWith('.md')
6969
);
7070
for (let i = 0; i < files.length; i += 1) {
7171
loadPipelines(instance, files[i]);
@@ -84,7 +84,7 @@ function loadPlugins(instance, fileName) {
8484
} else if (fs.existsSync(fileName)) {
8585
if (fs.lstatSync(fileName).isDirectory()) {
8686
const files = listFilesAbsolute(fileName).filter((x) =>
87-
x.endsWith(".js"),
87+
x.endsWith('.js')
8888
);
8989
for (let i = 0; i < files.length; i += 1) {
9090
loadPlugins(instance, files[i]);
@@ -98,8 +98,8 @@ function loadPlugins(instance, fileName) {
9898
}
9999

100100
function traverse(obj, preffix) {
101-
if (typeof obj === "string") {
102-
if (obj.startsWith("$")) {
101+
if (typeof obj === 'string') {
102+
if (obj.startsWith('$')) {
103103
return (
104104
process.env[`${preffix}${obj.slice(1)}`] || process.env[obj.slice(1)]
105105
);
@@ -109,7 +109,7 @@ function traverse(obj, preffix) {
109109
if (Array.isArray(obj)) {
110110
return obj.map((x) => traverse(x, preffix));
111111
}
112-
if (typeof obj === "object") {
112+
if (typeof obj === 'object') {
113113
const keys = Object.keys(obj);
114114
const result = {};
115115
for (let i = 0; i < keys.length; i += 1) {
@@ -126,14 +126,14 @@ function containerBootstrap(
126126
container,
127127
preffix,
128128
pipelines,
129-
parent,
129+
parent
130130
) {
131131
const mustLoadEnv = srcMustLoadEnv === undefined ? true : srcMustLoadEnv;
132132
const instance = container || new Container(preffix);
133133
instance.parent = parent;
134134
if (!preffix) {
135-
instance.register("fs", requestfs);
136-
instance.register("request", { get: request });
135+
instance.register('fs', requestfs);
136+
instance.register('request', { get: request });
137137
instance.use(ArrToObj);
138138
instance.use(Normalizer);
139139
instance.use(ObjToArr);
@@ -146,7 +146,7 @@ function containerBootstrap(
146146
}
147147
const srcSettings = inputSettings || {};
148148
let settings = srcSettings;
149-
if (typeof settings === "string") {
149+
if (typeof settings === 'string') {
150150
settings = {
151151
pathConfiguration: srcSettings,
152152
pathPipeline: defaultPathPipeline,
@@ -181,10 +181,10 @@ function containerBootstrap(
181181
configuration = settings;
182182
} else {
183183
configuration = JSON.parse(
184-
fs.readFileSync(settings.pathConfiguration, "utf8"),
184+
fs.readFileSync(settings.pathConfiguration, 'utf8')
185185
);
186186
}
187-
configuration = traverse(configuration, preffix ? `${preffix}_` : "");
187+
configuration = traverse(configuration, preffix ? `${preffix}_` : '');
188188
if (configuration.pathPipeline) {
189189
settings.pathPipeline = configuration.pathPipeline;
190190
}
@@ -197,18 +197,18 @@ function containerBootstrap(
197197
instance.registerConfiguration(
198198
keys[i],
199199
configuration.settings[keys[i]],
200-
true,
200+
true
201201
);
202202
}
203203
}
204204
if (configuration.use) {
205205
for (let i = 0; i < configuration.use.length; i += 1) {
206206
const current = configuration.use[i];
207-
if (typeof current === "string") {
207+
if (typeof current === 'string') {
208208
let infoArr = pluginInformation[current];
209209
if (!infoArr) {
210210
throw new Error(
211-
`Plugin information not found for plugin "${current}"`,
211+
`Plugin information not found for plugin "${current}"`
212212
);
213213
}
214214
if (!Array.isArray(infoArr)) {
@@ -228,7 +228,7 @@ function containerBootstrap(
228228
);
229229
} catch (err2) {
230230
throw new Error(
231-
`You have to install library "${info.path}" to use plugin "${current}"`,
231+
`You have to install library "${info.path}" to use plugin "${current}"`
232232
);
233233
}
234234
}
@@ -263,15 +263,15 @@ function containerBootstrap(
263263
instance.registerPipeline(
264264
pipeline.tag,
265265
pipeline.pipeline,
266-
pipeline.overwrite,
266+
pipeline.overwrite
267267
);
268268
}
269269
}
270-
loadPipelines(instance, settings.pathPipeline || "./pipelines.md");
270+
loadPipelines(instance, settings.pathPipeline || './pipelines.md');
271271
if (configuration.pipelines) {
272272
loadPipelinesStr(instance, configuration.pipelines);
273273
}
274-
loadPlugins(instance, settings.pathPlugins || "./plugins");
274+
loadPlugins(instance, settings.pathPlugins || './plugins');
275275
return instance;
276276
}
277277

packages/core/src/container.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class Container {
3333
* Constructor of the class.
3434
*/
3535
constructor(hasPreffix = false) {
36+
this.parent = undefined;
3637
this.classes = {};
3738
this.factory = {};
3839
this.pipelines = {};

packages/express-api-server/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@
2828
"@nlpjs/core": "^4.26.1",
2929
"cors": "^2.8.5",
3030
"express": "^4.21.1"
31+
},
32+
"devDependencies": {
33+
"supertest": "^7.0.0"
3134
}
3235
}

packages/lang-ja/src/stemmer-ja.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,8 @@ class StemmerJa extends BaseStemmer {
219219
* @param {String} srcStr Input string
220220
*/
221221
toRomaji(srcStr) {
222-
const reghatu = new RegExp(
223-
/(|)(?=|||||||||||||||||||||||||||||||)/g
224-
);
222+
const reghatu =
223+
/(|)(?=|||||||||||||||||||||||||||||||)/g;
225224
const indices = [];
226225
let str = srcStr;
227226
let match = reghatu.exec(str);

packages/lang-ko/src/korean-conjugation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ function conjugate(words, isAdjective) {
227227
lastChar,
228228
]
229229
);
230+
} else if (word.length === 1 && isAdjective) {
231+
expandedLast = [].concat(build(lastChar, [0, 2, 3, 6, 8, 9]), [lastChar]);
230232
} else if (word.length === 1 || (isAdjective && lastCoda === 'ㅆ')) {
231233
expandedLast = [].concat(build(lastChar, [0, 2, 3, 6, 8, 9, 10]), [
232234
lastChar,
233235
]);
234-
} else if (word.length === 1 && isAdjective) {
235-
expandedLast = [].concat(build(lastChar, [0, 2, 3, 6, 8, 9]), [lastChar]);
236236
} else {
237237
expandedLast = [lastChar];
238238
}

packages/lang-zh/src/stemmer-zh.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class StemmerZh {
6969
text = text.replace('?', ' ');
7070
text = text.replace('!', ' ');
7171
return text.replace(
72+
// eslint-disable-next-line prefer-regex-literals
7273
new RegExp('.:+-=()"\'!?،,؛;。,?!¥:;《》【】()', 'g'),
7374
' '
7475
);

packages/mongodb-adapter/src/mongodb-adapter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,20 @@ class MongodbAdapter extends Clonable {
120120
executeInCollection(name, fn) {
121121
return new Promise((resolve, reject) => {
122122
if (!this.db) {
123-
return reject(
123+
reject(
124124
new Error(
125125
'It seems that mongodb is not initialized, try invoking connect()'
126126
)
127127
);
128+
return;
128129
}
129130
const collection = this.db.collection(name);
130-
return fn(collection, (err, result) => {
131+
fn(collection, (err, result) => {
131132
if (err) {
132-
return reject(err);
133+
reject(err);
134+
} else {
135+
resolve(result);
133136
}
134-
return resolve(result);
135137
});
136138
});
137139
}

0 commit comments

Comments
 (0)