Skip to content

Commit

Permalink
fix: Remove rc-config-loader (#11)
Browse files Browse the repository at this point in the history
* remove rc-config-loader

* add js-yaml to dependencies

* remove js file support

* improve code

* add comment

* Update node-version

* remove no-use code
  • Loading branch information
HeRoMo authored Jul 1, 2021
1 parent f336ba1 commit 8982924
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10, 12, 14]
node-version: [ 12, 14, 16 ]
steps:
- name: checkout
uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Via `.textlintrc`(Recommended)
- `allowlistConfigPaths`: `string[]`
- File path list that includes allow words.
- The File path is relative path from your `.textlintrc`.
- Support file format: JSON, yml, js
- Support file format: JSON, yml
- Cannot use when using [@textlint/editor](https://github.com/textlint/editor)

For example, you can specify `allowlistConfigPaths` to `.textlintrc`.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@textlint/ast-node-types": "^12.0.0",
"@textlint/get-config-base-dir": "^2.0.0",
"@textlint/regexp-string-matcher": "^1.1.0",
"rc-config-loader": "^4.0.0"
"js-yaml": "^4.1.0"
},
"peerDependencies": {
"textlint": ">= 9.0.0"
Expand Down
25 changes: 18 additions & 7 deletions src/textlint-filter-rule-allowlist.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
import path from "path";
import { rcFile } from "rc-config-loader";
import yaml from "js-yaml";
import { getConfigBaseDir } from "@textlint/get-config-base-dir";
import { matchPatterns } from "@textlint/regexp-string-matcher";

const loadAllowlistConfigFile = (baseDirectory, filePath) => {
// It is for suppoting browser bundler.
const fs = require("fs");
const configFilePath = path.resolve(baseDirectory, filePath);
const extName = path.extname(configFilePath);
const configFile = fs.readFileSync(configFilePath);
if (extName == ".json") {
return JSON.parse(configFile);
} else if (/\.(yml|yaml)$/.test(extName)) {
return yaml.load(configFile);
}
throw new Error(`Unsupported file type: ${filePath}`);
};

const getAllowWordsFromFiles = (files, baseDirectory) => {
let results = [];
files.forEach((filePath) => {
// TODO: use other loader
const contents = rcFile("file", {
configFileName: path.resolve(baseDirectory, filePath)
});
if (contents && Array.isArray(contents.config)) {
results = results.concat(contents.config);
const config = loadAllowlistConfigFile(baseDirectory, filePath);
if (config && Array.isArray(config)) {
results = results.concat(config);
} else {
throw new Error(`This allow file is not allow word list: ${filePath}`);
}
Expand Down
12 changes: 1 addition & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2736,7 +2736,7 @@ [email protected]:
dependencies:
argparse "^2.0.1"

[email protected], js-yaml@^4.0.0:
[email protected], js-yaml@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
Expand Down Expand Up @@ -3884,16 +3884,6 @@ rc-config-loader@^3.0.0:
json5 "^2.1.1"
require-from-string "^2.0.2"

rc-config-loader@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/rc-config-loader/-/rc-config-loader-4.0.0.tgz#144cf31961c9f8ebcf252bd9c263fd40d62bd387"
integrity sha512-//LRTblJEcqbmmro1GCmZ39qZXD+JqzuD8Y5/IZU3Dhp3A1Yr0Xn68ks8MQ6qKfKvYCWDveUmRDKDA40c+sCXw==
dependencies:
debug "^4.1.1"
js-yaml "^4.0.0"
json5 "^2.1.2"
require-from-string "^2.0.2"

read-pkg-up@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02"
Expand Down

0 comments on commit 8982924

Please sign in to comment.