textlint-rule-terminology
Advanced tools
Comparing version 1.1.24 to 1.1.25
19
index.js
const fs = require('fs'); | ||
const path = require('path'); | ||
const stripJsonComments = require('strip-json-comments'); | ||
@@ -68,3 +69,2 @@ const { RuleHelper } = require('textlint-rule-helper'); | ||
const extras = typeof terms === 'string' ? loadJson(terms) : terms; | ||
return defaults.concat(extras); | ||
@@ -74,6 +74,20 @@ } | ||
function loadJson(filepath) { | ||
const json = fs.readFileSync(require.resolve(filepath), 'utf8'); | ||
const json = readTermsFile(path.resolve(filepath)); | ||
return JSON.parse(stripJsonComments(json)); | ||
} | ||
function readTermsFile(filepath) { | ||
try { | ||
return fs.readFileSync(filepath, 'utf8'); | ||
} | ||
catch (err) { | ||
if (err.code === 'ENOENT') { | ||
throw new Error(`Terms file not found: ${filepath}`); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
} | ||
function getRegExp(variants) { | ||
@@ -100,2 +114,3 @@ return new RegExp(`(?:^|[^-\\w])((?:${variants.join('|')})(?= |\\. |\\.$|$))`, 'ig'); | ||
test: { | ||
getTerms, | ||
getRegExp, | ||
@@ -102,0 +117,0 @@ getExactMatchRegExps, |
{ | ||
"name": "textlint-rule-terminology", | ||
"version": "1.1.24", | ||
"version": "1.1.25", | ||
"description": "TextLint rule to check correct terms spelling", | ||
@@ -24,3 +24,2 @@ "author": { | ||
"lint": "eslint . --fix", | ||
"semantic-release": "semantic-release pre && npm publish && semantic-release post", | ||
"test:jest": "jest", | ||
@@ -43,3 +42,2 @@ "test:watch": "jest --watch", | ||
"jest": "^21.0.1", | ||
"semantic-release": "^6.3.2", | ||
"semantic-release-tamia": "^1.1.1", | ||
@@ -58,2 +56,2 @@ "textlint-tester": "^2.2.4" | ||
} | ||
} | ||
} |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
5
192
2
11206
5