Skip to content

Commit 3503f8e

Browse files
authored
🐛 Commentつきのtsconfig.jsonに対応 (#6)
1 parent 997bac8 commit 3503f8e

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "eslint-plugin-strict-dependencies",
33
"description": "ESlint plugin to define custom module dependency rules.",
4-
"version": "0.0.2",
4+
"version": "1.0.0",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/knowledge-work/eslint-plugin-strict-dependencies.git"
88
},
9-
"keywords": [
9+
"keywords": [
1010
"eslint",
1111
"eslintplugin",
1212
"lint",
@@ -27,7 +27,8 @@
2727
"devDependencies": {
2828
"is-glob": "^4.0.3",
2929
"jest": "^27.2.4",
30-
"micromatch": "^4.0.4"
30+
"micromatch": "^4.0.4",
31+
"require-strip-json-comments": "^2.0.0"
3132
},
3233
"scripts": {
3334
"test": "jest --coverage"

strict-dependencies/resolveImportPath.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22

3-
const fs = require('fs')
43
const path = require('path')
4+
const parseJSON = require('require-strip-json-comments')
55

66
/**
77
* import文のrootからのパスを求める
@@ -13,9 +13,9 @@ module.exports = (importPath, relativeFilePath) => {
1313
// Load tsconfig option
1414
// MEMO: tscとか使って簡単に読める方法がありそう
1515
try {
16-
const tsConfigFile = fs.readFileSync(path.join(process.cwd(), '/tsconfig.json'), 'utf-8')
16+
const tsConfigFilePath = path.join(process.cwd(), '/tsconfig.json')
1717
// Exists ts config
18-
const tsConfig = JSON.parse(tsConfigFile)
18+
const tsConfig = parseJSON(tsConfigFilePath)
1919
if (tsConfig.compilerOptions && tsConfig.compilerOptions.paths) {
2020
Object.keys(tsConfig.compilerOptions.paths).forEach((key) => {
2121
// FIXME: このlint ruleではimport先が存在するかチェックしておらず、複数のパスから正しい方を選択できないため[0]固定

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,13 @@ require-directory@^2.1.1:
20982098
resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42"
20992099
integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I=
21002100

2101+
require-strip-json-comments@^2.0.0:
2102+
version "2.0.0"
2103+
resolved "https://registry.yarnpkg.com/require-strip-json-comments/-/require-strip-json-comments-2.0.0.tgz#71733597bdd5c8581e1c01af485e3540ddc1f5a4"
2104+
integrity sha512-Pta3KVBaVZ9DHMoOGRd+3PEc/EFZAQ1JVHQpKZfPo018fdT9iEsyPBzqNAgJAzKMF4kbr5G7GaqP0+UOwnGfPw==
2105+
dependencies:
2106+
strip-json-comments "^3.0"
2107+
21012108
resolve-cwd@^3.0.0:
21022109
version "3.0.0"
21032110
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"
@@ -2250,6 +2257,11 @@ strip-final-newline@^2.0.0:
22502257
resolved "https://registry.yarnpkg.com/strip-final-newline/-/strip-final-newline-2.0.0.tgz#89b852fb2fcbe936f6f4b3187afb0a12c1ab58ad"
22512258
integrity sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==
22522259

2260+
strip-json-comments@^3.0:
2261+
version "3.1.1"
2262+
resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-3.1.1.tgz#31f1281b3832630434831c310c01cccda8cbe006"
2263+
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==
2264+
22532265
supports-color@^5.3.0:
22542266
version "5.5.0"
22552267
resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-5.5.0.tgz#e2e69a44ac8772f78a1ec0b35b689df6530efc8f"

0 commit comments

Comments
 (0)