[eslint] 절대경로 설정하기

·2022년 9월 25일
0

공부한 것

목록 보기
30/58
{
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["src"] //절대경로 설정
      }
    }
  }
}

위 코드는 프로젝트에서 절대 경로를 설정했을 때 eslint도 맞춰 설정하는 코드이다.
절대 경로를 사용하는 경우 src폴더부터 시작하기 때문에 import 사용 시 에러가 날 수 있어 맞춰주는 것이다.

한 줄씩 보자면

  1. settings 속성은 모든 규칙에 의해 공유되는 설정을 하는 부분이다. 커스텀 설정 할 때 쓰인다고 되어있다.

    You can add settings object to ESLint configuration file and it will be supplied to every rule being executed
    Adding Shared Settings

  2. import/resolvereslint-plugin-import의 경로 설정 옵션이라고 한다.
    package.json을 보면 eslint-plugin-import가 설치된 것을 확인할 수 있다.

  3. node node.js 환경을 말하는 것 같다....

  4. "paths": ["src"] src부터 경로가 시작할 수 있도록 설정하는 것이다.

settings:
  import/resolver:
    node:
      extensions:
        # if unset, default is just '.js', but it must be re-added explicitly if set
        - .js
        - .jsx
        - .es6
        - .coffee

      paths:
        # an array of absolute paths which will also be searched
        # think NODE_PATH
        - /usr/local/share/global_modules

      # this is technically for identifying `node_modules` alternate names
      moduleDirectory:

        - node_modules # defaults to 'node_modules', but...
        - bower_components

        - project/src  # can add a path segment here that will act like
                       # a source root, for in-project aliasing (i.e.
                       # `import MyStore from 'stores/my-store'`)

eslint-plugin-importyarn 사이트에서 가져왔다.

참고자료

0개의 댓글