์ง์ ‘์ ์ธ ์†์˜ ์ˆฒ์ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ๋ฌผ๊ฑด์„ ์ •๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•(tslint, prettier ๋“ฑ ์„ค์ •)

๋‹ค์‹œ ์•ˆ๋…•ํ•˜์„ธ์š”. ์—ฐ๋ฝํ•˜๋‹ค ์˜ค๋ฉœ๋‹ˆ์ธ ํ‚ค ์„ธ๋ฅด๊ฒŒ์ด. ์˜ค๋Š˜์€ ์ œ๊ฐ€ ๊ณจ์น˜ ์•„ํ”ˆ ๋ฌธ์ œ ์ค‘ ํ•˜๋‚˜, ์ฆ‰ Angular ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์˜ˆ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋งŽ์€ ๋‹ค๋‹จ๊ณ„ ํ”„๋กœ๊ทธ๋ž˜๋จธ๊ฐ€ ํ”„๋กœ์ ํŠธ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ์–ด๋–ป๊ฒŒ ํ•ด์•ผ ํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ๊ณต์œ ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์ง์ ‘์ ์ธ ์†์˜ ์ˆฒ์ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ๋ฌผ๊ฑด์„ ์ •๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•(tslint, prettier ๋“ฑ ์„ค์ •)

๊ทธ๋ž˜์„œ ๋‚˜๋Š” ์˜ค๋žซ๋™์•ˆ ์„œ์‹, ์ฃผ์„ ๋‹ฌ๊ธฐ, ๋“ค์—ฌ์“ฐ๊ธฐ ๋“ฑ์˜ ๊ทœ์น™์— ๋Œ€ํ•ด ์˜ค๋žซ๋™์•ˆ ํ•ฉ์˜ํ•ด ์˜จ ์šฐ๋ฆฌ ํŒ€๊ณผ๋งŒ ์ผํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋“ค์€ ๊ทธ๋“ค์—๊ฒŒ ์ต์ˆ™ํ•ด์กŒ๊ณ  ์šฐํ˜ธ์ ์ด๊ณ  ํ–‰๋ณตํ•˜๊ฒŒ ์‚ด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์ถ•ํ•˜ํ•˜๊ธฐ ์œ„ํ•ด Habr์— ๊ธฐ์‚ฌ๋ฅผ ๊ฒŒ์žฌํ•˜๊ธฐ๋„ ํ–ˆ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ์˜ ์ฝ”๋“œ ์Šคํƒ€์ผ. ๋”ฐ๋ผ์„œ ๋งˆ๋ฒ•๊ฐ™์€ ์ผ์„ ํ•˜๊ธฐ ์œ„ํ•ด ์šฐ๋ฆฌ๋Š” ์‚ฌ์ „ ์ปค๋ฐ‹์—์„œ๋งŒ tslint๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ์šฐ๋ฆฌ๋Š” ์„ฑ์žฅํ–ˆ์Šต๋‹ˆ๋‹ค. ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ƒˆ๋กœ์šด ํ”„๋กœ์ ํŠธ๊ฐ€ ๋“ฑ์žฅํ–ˆ๊ณ , ๊ทธ ์™ธ์—๋„ 4๋ช…์˜ ์ข‹์€ ๋™๋ฃŒ๋“ค์ด ์ƒˆ๋กœ์šด ๊ฐœ๋ฐœ์ž๋กœ ํ•ฉ๋ฅ˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ผ์ด ๊ณ„ํš๋Œ€๋กœ ์ง„ํ–‰๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

์ง์ ‘์ ์ธ ์†์˜ ์ˆฒ์ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ๋ฌผ๊ฑด์„ ์ •๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•(tslint, prettier ๋“ฑ ์„ค์ •)

๋งŽ์€ ์‚ฌ๋žŒ๋“ค์ด ๋ ˆ๊ฑฐ์‹œ ์ฝ”๋“œ๋กœ ์ž‘์—…ํ•˜๋Š” ๊ฒƒ์ด ์žฌ๋ฏธ์—†๋‹ค๋Š” ๊ฒƒ์„ ์•Œ๊ณ  ์žˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. ์ œ ๊ธฐ์–ต์œผ๋กœ๋Š” ๊ธฐ๋ปค๋˜ ํ”„๋กœ์ ํŠธ๊ฐ€ ๋”ฑ ํ•˜๋‚˜ ์žˆ์—ˆ๋Š”๋ฐ ๋‚˜๋จธ์ง€๋Š”... ๊ทธ๋Ÿผ ๋ฌด์Šจ ๋ง์„ ํ•˜๋Š” ๊ฑธ๊นŒ์š”?) ์•„ ๊ทธ๋ ‡๊ตฐ์š”.

์†”์งํžˆ ๋งํ•ด์„œ ํ”„๋กœ์ ํŠธ์˜ ์•„ํ‚คํ…์ฒ˜๋Š” ์•„์‰ฌ์šด ์ ์ด ๋งŽ์•˜๊ณ  ์šฐ๋ฆฌ๋Š” ๋Œ“๊ธ€๊ณผ ํƒ€์ดํ•‘๋งŒ์„ ๊ฟˆ๊ฟจ์Šต๋‹ˆ๋‹ค. ์–ด๋А ์‹œ์ ์—์„œ ๋‚˜๋Š” ๋””์ž์ธ ๊ทœ์น™์— ๋”ฐ๋ฅธ ๋ฌธ์„œ๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๊ณ  ๋Œ“๊ธ€์ด ์ž‘์„ฑ๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ์šฐ์šธํ•ด์กŒ์Šต๋‹ˆ๋‹ค. "์ด๊ฒŒ ๋ญ์ฃ ?). ์ด์— ๋Œ€ํ•ด ๋ญ”๊ฐ€ ์กฐ์น˜๋ฅผ ์ทจํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  ๋‹จ๊ณ„๋ฅผ ํ•œ ๋ฒˆ์— ๋ฐฐ์šฐ๊ณ  ์‹ถ์€ ๋ถ„๋“ค์„ ์œ„ํ•ด:

  • ์šฐ๋ฆฌ๋Š” tslint๋ฅผ ์†Œํ”„ํŠธ ๊ทœ์น™(์‚ฌ์ „ ์ปค๋ฐ‹์šฉ)๊ณผ ํ•˜๋“œ ๊ทœ์น™(๊ฐœ๋ฐœ์ž๊ฐ€ ์žŠ์–ด๋ฒ„๋ฆฐ ์ž‘์—…์„ ์ƒ๊ธฐ์‹œํ‚ค๊ธฐ ์œ„ํ•ด)์œผ๋กœ ๋‚˜๋ˆ„์—ˆ์Šต๋‹ˆ๋‹ค.

  • ํ•˜๋“œ tslint์—์„œ ์‚ฌ์ „ ์ปค๋ฐ‹๊นŒ์ง€ ๊ฐ€๋Šฅํ•œ ๊ทœ์น™์˜ ์ž๋™ ์ˆ˜์ •์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.

  • ๋” ์˜ˆ๋ป์ง€๊ธฐ ์œ„ํ•œ ๊ทœ์น™์„ ์ผ์Šต๋‹ˆ๋‹ค

  • ์šฐ๋ฆฌ๋Š” ํƒฌ๋ฒ„๋ฆฐ๊ณผ ํ•จ๊ป˜ ์ถค์„ ์ถ”๋ฉฐ lint-staged๋กœ ng lint๋ฅผ ๋ฐœ์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค.

XNUMX๋‹จ๊ณ„ - ๋ถ„์—ด๊ณผ ์ •๋ณต

๋ฆฐํ„ฐ์˜ ๊ทœ์น™์„ ๊ฐ•ํ™”ํ•˜์ž๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ์„ ๋•Œ ๋‚˜๋Š” ์šฐ๋ฆฌ๊ฐ€ ๋ชฉ์„ ๋งค์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ๋Š” ๋ ˆ๊ฑฐ์‹œ์ž…๋‹ˆ๋‹ค. ๋‹น์‹ ์€ ๊ทธ๊ฒƒ์„ ์ดํ•ดํ•ด์•ผํ•˜์ง€๋งŒ ๊ทธ๋Ÿฌํ•œ ๋ณผ๋ฅจ์—์„œ๋Š” ๋‹น์‹  ์ž์‹ ์„ ๋ฌป์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ide์— ๋Œ€ํ•œ ๋‘ ๋ฒˆ์งธ linter๋ฅผ ๋งŒ๋“ค๊ธฐ๋กœ ๊ฒฐ์ •ํ–ˆ๋Š”๋ฐ, ์ด๋Š” ๋ˆˆ์— ๊ฑฐ์Šฌ๋ฆฌ๊ณ  ๋ฉ”์†Œ๋“œ ๋ฐ ์†์„ฑ์— ๋Œ€ํ•ด jsdoc๋ฅผ ์ž‘์„ฑํ•˜๊ณ , ์ธํ„ฐํŽ˜์ด์Šค ๋˜๋Š” ๋ถˆํ–‰ํ•œ onPush ๋“ฑ์„ ์ž‘์„ฑํ•˜๋„๋ก ๊ฐ•์š”ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๋ฃจํŠธ์—์„œ ์šฐ๋ฆฌ๋Š” 2๊ฐœ์˜ tslin ํŒŒ์ผ์„ ๊ฐ–๊ธฐ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค:

tsconfig.json

{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
    "arrow-return-shorthand": true,
    "callable-types": true,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "deprecation": {
      "severity": "warn"
    },
    "eofline": true,
    "forin": true,
    "import-blacklist": [
      true,
      "rxjs/Rx"
    ],
    "import-spacing": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "label-position": true,
    "max-line-length": [
      true,
      200
    ],
    "member-access": false,
    "member-ordering": [
      true,
      {
        "order": [
          "static-field",
          "instance-field",
          "static-method",
          "instance-method"
        ]
      }
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": [
      true,
      "debug",
      "info",
      "time",
      "timeEnd",
      "trace"
    ],
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-super": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-eval": true,
    "no-inferrable-types": [
      false,
      "ignore-params"
    ],
    "no-duplicate-imports": true,
    "no-misused-new": true,
    "no-non-null-assertion": true,
    "no-redundant-jsdoc": true,
    "no-shadowed-variable": false,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": [
      true,
      "ignore-comments",
      "ignore-jsdoc"
    ],
    "no-unnecessary-initializer": true,
    "no-unused-expression": true,
    "no-use-before-declare": false,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": false,
    "semicolon": [
      true,
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],
    "directive-selector": [
      true,
      "attribute",
      "app",
      "camelCase"
    ],
    "component-selector": [
      true,
      "element",
      "app",
      "kebab-case"
    ],
    "no-output-on-prefix": false,
    "no-inputs-metadata-property": true,
    "no-outputs-metadata-property": true,
    "no-host-metadata-property": true,
    "no-input-rename": false,
    "no-output-rename": true,
    "use-lifecycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": true,
    "directive-class-suffix": true,
    "no-consecutive-blank-lines": true
  }
}

tslint.ide_only.json

{
  "rulesDirectory": [
    "node_modules/codelyzer"
  ],
  "rules": {
    "completed-docs": [
      true,
      {
        "properties": true,
        "methods": true
      }
    ],
    "no-angle-bracket-type-assertion": true,
    "no-any": true,
    "prefer-output-readonly": true,
    "prefer-on-push-component-change-detection": true,
    "array-type": [
      true,
      "array"
    ],
    "typedef": [
      true,
      "call-signature",
      "arrow-call-signature"
    ],
    "arrow-return-shorthand": true,
    "callable-types": true,
    "class-name": true,
    "comment-format": [
      true,
      "check-space"
    ],
    "curly": true,
    "deprecation": {
      "severity": "warn"
    },
    "eofline": true,
    "forin": true,
    "import-blacklist": [
      true,
      "rxjs/Rx"
    ],
    "import-spacing": true,
    "indent": [
      true,
      "spaces"
    ],
    "interface-over-type-literal": true,
    "label-position": true,
    "max-line-length": [
      true,
      200
    ],
    "member-access": [
      true,
      "check-parameter-property",
      "check-accessor"
    ],
    "member-ordering": [
      true,
      {
        "order": [
          "public-static-field",
          "protected-static-field",
          "private-static-field",
          "public-instance-field",
          "protected-instance-field",
          "private-instance-field",
          "constructor",
          "public-static-method",
          "protected-static-method",
          "private-static-method",
          "public-instance-method",
          "protected-instance-method",
          "private-instance-method"
        ]
      }
    ],
    "no-arg": true,
    "no-bitwise": true,
    "no-console": true,
    "no-construct": true,
    "no-debugger": true,
    "no-duplicate-super": true,
    "no-empty": false,
    "no-empty-interface": true,
    "no-duplicate-switch-case": true,
    "no-eval": true,
    "no-inferrable-types": [
      false,
      "ignore-params"
    ],
    "no-duplicate-imports": true,
    "one-variable-per-declaration": true,
    "no-misused-new": true,
    "no-non-null-assertion": true,
    "prefer-template": [
      true,
      "allow-single-concat"
    ],
    "ordered-imports": true,
    "no-redundant-jsdoc": true,
    "no-shadowed-variable": false,
    "no-string-literal": false,
    "no-string-throw": true,
    "no-switch-case-fall-through": true,
    "no-trailing-whitespace": [
      true,
      "ignore-comments",
      "ignore-jsdoc"
    ],
    "ban": [
      true,
      {
        "name": [
          "Object",
          "assign"
        ],
        "message": "ะ˜ัะฟะพะปัŒะทัƒะนั‚ะต cloneDeep (lodash) ะดะปั ะบะพะฟะธั€ะพะฒะฐะฝะธั ะพะฑัŠะตะบั‚ะฐ"
      }
    ],
    "max-classes-per-file": [
      true,
      1
    ],
    "cyclomatic-complexity": [
      true,
      6
    ],
    "static-this": true,
    "no-unnecessary-initializer": true,
    "no-unused-expression": true,
    "no-var-keyword": true,
    "object-literal-sort-keys": false,
    "one-line": [
      true,
      "check-open-brace",
      "check-catch",
      "check-else",
      "check-whitespace"
    ],
    "prefer-const": true,
    "quotemark": [
      true,
      "single"
    ],
    "radix": false,
    "semicolon": [
      true,
      "always"
    ],
    "triple-equals": [
      true,
      "allow-null-check"
    ],
    "typedef-whitespace": [
      true,
      {
        "call-signature": "nospace",
        "index-signature": "nospace",
        "parameter": "nospace",
        "property-declaration": "nospace",
        "variable-declaration": "nospace"
      }
    ],
    "unified-signatures": true,
    "variable-name": false,
    "whitespace": [
      true,
      "check-branch",
      "check-decl",
      "check-operator",
      "check-separator",
      "check-type"
    ],
    "directive-selector": [
      true,
      "attribute",
      "app",
      "camelCase"
    ],
    "component-selector": [
      true,
      "element",
      "app",
      "kebab-case"
    ],
    "no-output-on-prefix": false,
    "no-inputs-metadata-property": true,
    "no-outputs-metadata-property": true,
    "no-host-metadata-property": true,
    "no-input-rename": false,
    "no-output-rename": true,
    "use-lifecycle-interface": true,
    "use-pipe-transform-interface": true,
    "component-class-suffix": true,
    "directive-class-suffix": true,
    "no-consecutive-blank-lines": true
  }
}

ํŒŒ์ผ์—์„œ src/tslint ์šฐ๋ฆฌ๋Š” ํ‘œ์ค€ tslint๋ฅผ ide๋กœ ๋Œ€์ฒดํ–ˆ์Šต๋‹ˆ๋‹ค.

src/tslint.json

{
    "extends": "../tslint.ide_only.json",
    "rules": {
        "directive-selector": [
            true,
            "attribute",
            "app",
            "camelCase"
        ],
        "component-selector": [
            true,
            "element",
            "app",
            "kebab-case"
        ]
    }
}

๊ทธ๋ฆฌ๊ณ  package.json ์Šคํฌ๋ฆฝํŠธ์—์„œ linter์˜ ์‹œ์ž‘์„ ์ˆ˜์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

ng lint --tslint-config ./tslint.json --fix`

๊ทธ ์ดํ›„๋กœ ์šฐ๋ฆฌ๋Š” ๋ฐ”๋กœ์žก์•„์•ผ ํ•  ์ ์„ ๊ฐ•์กฐํ•˜๋Š” ์ผ์„ ๊ทธ๋งŒ๋‘๊ธฐ ์‹œ์ž‘ํ–ˆ์Šต๋‹ˆ๋‹ค.

XNUMX๋‹จ๊ณ„ - ๋ช‡ ๊ฐ€์ง€ ๋ฌธ์ œ ์ˆ˜์ •

์ง์ ‘์ ์ธ ์†์˜ ์ˆฒ์ด ์žˆ๋Š” ํ”„๋กœ์ ํŠธ์—์„œ ๋ฌผ๊ฑด์„ ์ •๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ•(tslint, prettier ๋“ฑ ์„ค์ •)

tslint์—๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ทœ์น™์ด ์žˆ์Šต๋‹ˆ๋‹ค. has fixer. ๊ทธ๋Ÿผ ์‚ฌ์šฉํ•ด ๋ด…์‹œ๋‹ค.

tslint --project tslint.ide_only.json --fix --force

์—ฌ๊ธฐ์„œ๋Š” ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ์ž๋™ ์ˆ˜์ •ํ•˜๋Š” ํ•˜๋“œ ๋ฆฐํ„ฐ ๊ทœ์น™์„ ์‹คํ–‰ํ•˜๊ณ  ์ด ๋ช…๋ น์— ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜์ง€ ์•Š๋„๋ก ์ง€์‹œํ•ฉ๋‹ˆ๋‹ค(์—ฌ๊ธฐ์„œ ์šฐ๋ฆฌ์˜ ๋ชฉํ‘œ๋Š” ๊ฒฐ๊ตญ ์ž๋™ ์ˆ˜์ •์„ ์ˆ˜ํ–‰ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค).

XNUMX๋‹จ๊ณ„ - ์•„๋ฆ„๋‹ต๊ฒŒ ์“ฐ๊ธฐ

๋‹ค๋“ค ์ž๊ธฐ ๋ฐฉ์‹๋Œ€๋กœ ๊ธ€์„ ์“ฐ๋‹ค ๋ณด๋ฉด ๊ฒฐ๊ตญ ์ง€๋ฃจํ•ด์ง€๊ฑฐ๋“ ์š”. ์ฝ”๋“œ๋Š” ๋งˆ์น˜ ํ•œ ์‚ฌ๋žŒ์ด ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์ž‘์„ฑ๋˜์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ์œ„ํ•ด ๋‹ค์Œ ์„ค์ •์œผ๋กœ Pretier๋ฅผ ์„ค์น˜ํ–ˆ์Šต๋‹ˆ๋‹ค.

.prettierr.yaml

printWidth: 200     # ะœะฐะบัะธะผะฐะปัŒะฝะพะต ะบะพะป-ะฒะพ ัะธะผะฒะพะปะพะฒ ะฒ ัั‚ั€ะพะบะต
tabWidth: 2         # ะŸั€ะพะฑะตะปะพะฒ ะฒ ะขะฐะฑะต
singleQuote: true   # ะ˜ัะฟะพะปัŒะทะพะฒะฐั‚ัŒ ะพะดะธะฝะฐั€ะฝั‹ะต ะบะฐะฒั‹ั‡ะบะธ
trailingComma: all  # ะ˜ัะฟะพะปัŒะทะพะฒะฐั‚ัŒ ะทะฐะฟัั‚ั‹ะต ะณะดะต ะฒะพะทะผะพะถะฝะพ
arrowParens: always # ะกั‚ั€ะตะปะพั‡ะฝั‹ะต ั„-ะธะธ ะฒั‹ะณะปัะดัั‚ (x) => x
overrides:
  - files: "*.ts"   # ะŸั€ะพะฒะตั€ะบะฐ ั„ะฐะนะปะพะฒ *.ts
    options:
      parser: typescript  # ะฏะทั‹ะบ ะฒ ั„ะฐะนะปะฐั… *.ts

๊ทธ๋ฆฌ๊ณ  ๋‹ค์Œ ๋ช…๋ น์„ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค. prettier --write --config .prettierr.yaml

XNUMX๋‹จ๊ณ„ - ์ด ๋ชจ๋“  ๊ฒƒ์„ ์–ด๋–ป๊ฒŒ ์‹œ์ž‘ํ•  ์˜ˆ์ •์ž…๋‹ˆ๊นŒ?

์ด์ œ ์ด ๋ชจ๋“  ๊ฒƒ์„ ์‹œ์ž‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ž์„ธํžˆ ์‚ดํŽด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์ด ์ž‘๋™ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

npm i -D prettier lint-staged husky

Husky๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ git ํ›„ํฌ์—์„œ ๋ช…๋ น ์‹คํ–‰์„ ์ค‘๋‹จํ•ฉ๋‹ˆ๋‹ค(์‚ฌ์ „ ์ปค๋ฐ‹). lint-staged๋Š” ๋ณ€๊ฒฝ๋œ ํŒŒ์ผ์— ๋”ฐ๋ผ ๋ช…๋ น์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค(๋˜ํ•œ ์ด ํŒŒ์ผ์„ ๋ช…๋ น์œผ๋กœ ๋Œ€์ฒดํ•ฉ๋‹ˆ๋‹ค).

์ œ๊ฐ€ ์ง๋ฉดํ•œ ๋ฌธ์ œ๋ฅผ ์ฆ‰์‹œ ์„ค๋ช…ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ์šฐ๋ฆฌ ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ng lint๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. lint-staged์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋ฉด ์ˆ˜์ •๋œ ํŒŒ์ผ์ด ๋ช…๋ น์— ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค. ng lint์— ์ด์— ๋Œ€ํ•œ ํ‚ค๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค --files, ๊ทธ๋Ÿฌ๋‚˜ ๋‚ด๊ฐ€ ์ดํ•ดํ•œ ๋ฐ”์— ๋”ฐ๋ฅด๋ฉด ๊ทธ๋Š” ๋งŽ์€ ํŒŒ์ผ์„ ๋ณผ ์ˆ˜ ์—†์œผ๋ฉฐ ๊ฐ ํŒŒ์ผ์— ์ด ํ‚ค๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ ค๋ฉด ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค.

lint.sh

#!/bin/bash

PROJECT=$1
shift
SOURCES=$@
DESTINATIONS=""
DELIMITER=""

for src in $SOURCES
do
    DELIMITER=" --files "
    DESTINATIONS="$DESTINATIONS$DELIMITER${src}"
done

ng lint $PROJECT --tslint-config ./tslint.json $DESTINATIONS

์ด ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ํ”„๋กœ์ ํŠธ ์ด๋ฆ„์„ ์ „๋‹ฌํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ํŒŒ์ผ์— ์žˆ์–ด์š” angular.json ํ”„๋กœ์ ํŠธ ์†์„ฑ์—์„œ. ๋‚ด ๊ฒฝ์šฐ์—๋Š” ๊ทธ๋ ‡์ง€ partner-account ะธ partner-account-e2e. ์ฒซ ๋ฒˆ์งธ๊ฐ€ ํ•„์š”ํ•ด์š”.

์„ค์ •์œผ๋กœ ๋Œ์•„๊ฐ€ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. package.json์€ ์ด์ œ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  "husky": {
    "hooks": {
      "pre-commit": "lint-staged --relative"
    }
  },
  "lint-staged": {
    "*.{ts,js}": [
      "prettier --write --config .prettierr.yaml",
      "tslint --project tslint.ide_only.json --fix --force",
      "sh lint.sh partner-account",
      "git add"
    ],
    "*.{html,scss,css}": [
      "prettier --write --config .prettierr.yaml",
      "git add"
    ]
  },

์ฃผ์˜๋ฅผ ๊ธฐ์šธ์ด์‹ญ์‹œ์˜ค. lint-staged --relative. ๋ชจ์ˆ˜ --relative ๊ฑฐ๊ธฐ์— ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์ด์ œ ์ปค๋ฐ‹ํ•˜๋ฉด ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. lint-staged. ๊ทธ๋Ÿฐ ๋‹ค์Œ ํŒŒ์ผ์„ ์„ ํƒํ•˜๊ณ  ํ•ด๋‹น ํŒŒ์ผ์— ๋”ฐ๋ผ ๋ช…๋ น ๋ชฉ๋ก์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

์•„์‰ฝ๊ฒŒ๋„ ์ฝ”๋“œ ๊ฒ€ํ† ๊ฐ€ ์ทจ์†Œ๋˜์ง€๋Š” ์•Š์ง€๋งŒ ํ›จ์”ฌ ๊น”๋”ํ•ด์กŒ์Šต๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์ž์—๊ฒŒ ์•ก์„ธ์Šค ํ•œ์ •์ž, ๋ฉ”์„œ๋“œ ๋ฐ ์†์„ฑ ์„ค๋ช…์— ๋Œ€ํ•ด ๋œ ์ž์ฃผ ์ƒ๊ธฐ์‹œํ‚ค๊ธฐ ์‹œ์ž‘ํ–ˆ๊ณ  ๊ทธ๋“ค์˜ ์ž‘์—…์ด ๋™์ผํ•œ ์Šคํƒ€์ผ๋กœ ์ž‘์„ฑ๋˜๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค๋Š” ์ ์— ์ฃผ๋ชฉํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค(๊ฑฐ์˜ ๐Ÿ˜€).

์ถ”์‹  - PM์—๊ฒŒ ์‚ฌ์ง„์„ ๋ณด๋‚ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค.

์ถœ์ฒ˜ : habr.com

DDoS ๋ณดํ˜ธ, VPS VDS ์„œ๋ฒ„๊ฐ€ ์žˆ๋Š” ์‚ฌ์ดํŠธ๋ฅผ ์œ„ํ•œ ์•ˆ์ •์ ์ธ ํ˜ธ์ŠคํŒ… ๊ตฌ์ž… ๐Ÿ”ฅ DDoS ๊ณต๊ฒฉ ๋ฐฉ์ง€ ๊ธฐ๋Šฅ์ด ํƒ‘์žฌ๋œ ์•ˆ์ •์ ์ธ ์›น์‚ฌ์ดํŠธ ํ˜ธ์ŠคํŒ…, VPS ๋ฐ VDS ์„œ๋ฒ„๋ฅผ ๊ตฌ๋งคํ•˜์„ธ์š” | ProHoster