Lintest CLI
Copyright 2020. mornya. All rights reserved.
About
Integrated lint and test environment project.
Features
- TypeScript / ES6+ support with TypeScript.
- Linting TypeScript / JavaScript codes with ESLint.
- Testing codes with Jest.
- All available for Node.js / React.js / Vue.js (Nuxt.js) application
Installation
ํด๋น ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๊ธ๋ก๋ฒ๋ก ์ค์นํ๊ฑฐ๋ ํ๋ก์ ํธ ๋ด์ ์ค์นํ ์ ์๋ค.
npm ๋์ yarn ์ฌ์ฉ์, ํ๋ก์ ํธ ๋ฃจํธ ๊ฒฝ๋ก์ package-lock.json ํ์ผ์ด ์กด์ฌํ๋ฉด ์ ๊ฑฐํ๊ณ yarn.lock ํ์ผ๋ง ์ฐธ์กฐ๋๋๋ก ํ๋ค.
$ npm install --save-dev @lintest/cli
or
$ yarn add -D @lintest/cli
๊ธ๋ก๋ฒ ์ค์น๋ฅผ ์ํด์๋ ์๋์ ๊ฐ์ด ์คํํ๋ค.
$ npm install -g @lintest/cli
or
$ yarn global add @lintest/cli
Execution
CLI
lintest ํ๊ฒฝ์ค์ ์ ํ๋ก์ ํธ ๋ฃจํธ ๊ฒฝ๋ก์ lintest.config.js ํ์ผ๋ก ์์ฑํ๋ฉด ๋๋ค.
ํด๋น ํ์ผ์ด ์กด์ฌํ๋ฉด lintest install ๋ช
๋ น ์ํ์ providerํญ๋ชฉ์ผ๋ก ์ง์ ๋ ๋ํ๋์๊ฐ ํ๋ก์ ํธ์ ์ค์น๋๋ฉฐ, ๋ฆฐํธ ๋ฃฐ์ ํด๋น ๋ํ๋์ ์ค์ ์ ๋ฐ๋ฅด๊ฒ ๋๋ค.
module.exports = {
provider: 'sample',
}
์์ ๊ฐ์ด ์ค์ ํ๋ฉด lintest install ๋ช
๋ น ์คํ์ @lintest/rules-sample ๋ํ๋์๊ฐ ํ๋ก์ ํธ ๋ด ์ค์น๊ฐ ๋๋ฉฐ lint rule์ ํด๋น ๋ํ๋์ ๋ด ์ค์ ์ ๋ฐ๋ฅธ๋ค.
๋ฆฐํธ ๋ฐ ํ
์คํธ ์ํ์ CLI๋ก ์คํํ๋ค. lintest๊ฐ ๊ธ๋ก๋ฒ ๋ชจ๋๋ก ์ค์น ๋์ด์๋ ๊ฒฝ์ฐ ์ปค๋งจ๋๋ผ์ธ์์ ์๋์ ๊ฐ์ด ์คํ ํ ์ ์๋ค.
$ lintest lint [fix|debug]
$ lintest test [watch|coverage]
๋ฆฐํธ ๋ฐ ํ
์คํธ ํ๊ฒฝ์ค์ ๋ด์ฉ์ด ํ์ํ ๊ฒฝ์ฐ export ๋ช
๋ น์ ์ฌ์ฉํ์ฌ ํ๊ฒฝ์ค์ ์ ์ฐธ๊ณ ํ ์ ์๋ค.
์ํ๊ฒฐ๊ณผ๋ ํ๋ก์ ํธ ๋ฃจํธ ๊ฒฝ๋ก์ eslint.config.json ๋ฐ jest.config.json ํ์ผ์ด ์์ฑ๋๋ค.
๋ง์ฝ ์ ์์ ์ธ ์ถ๋ ฅ์ด ๋์ง ์๋๋ค๋ฉด debug ํ๋ผ๋ฏธํฐ๋ก ํ์ธํ๋ค.
$ lintest export [debug]
NPM
NPM ํ๋ก์ ํธ์์๋ npm run ๋ช
๋ น์ผ๋ก ์คํ๋๋๋ก ์๋์ ๊ฐ์ด package.json ํ์ผ ๋ด์ ์ค์ ํ๋ค.
{
"scripts": {
"lint": "lintest lint",
"lint:fix": "lintest lint fix",
"lint:debug": "lintest lint debug",
"test": "lintest test",
"test:watch": "lintest test watch",
"test:coverage": "lintest test coverage"
}
}
Test setup files
๊ฐ ๋จ์ ํ
์คํธ๋ฅผ ์ํํ๊ธฐ ์ mocking method๋ ์ด๊ธฐ ์ค์ ์ ํ ์ ์๋๋ก ์
์
ํ์ผ์ ์ถ๊ฐ ํ ์ ์๋ค.
์ ์ฉ๋ ํ
์คํธ ์
์
ํ์ผ์ ์๋ ๋ชฉ๋ก์์ ์กด์ฌํ๋ ํ์ผ์ ์ฐพ์ ์ฌ์ฉํ๊ฒ ๋๋ค.
์์ธํ ๋ด์ฉ์ Jest ๊ด๋ จ ๋ฌธ์๋ฅผ ์ฐธ๊ณ .
<rootDir>/src/test/@setup.ts (or .js)
<rootDir>/test/@setup.ts (or .js)
<rootDir>/test-setup.ts (or .js)
Lint rule module
main ํ์ผ์ ์๋์ ๊ฐ์ ํํ์ lint rule ์ ์ ํ์ผ๋ง ํ์ํ๋ค.
lintRules ํ์ ํญ๋ชฉ์ ๋ฃฐ๋ค์ prefix๋ฅผ ๋ถ์ด์ง ์์๋ ๋๋ค.
typescript ํญ๋ชฉ์ '@typescript-eslint/indent' ๋ฃฐ์ ์ ์ํ ๋ '@typescript-eslint/'๋ ๊ตณ์ด ๋ถ์ฌ์ฃผ์ง ์์๋ 'typescript' ํญ๋ชฉ ํ์์ ์ ์ธํ๋ฉด prefix๋ '@typescript-eslint/'๋ก ์๋ ๊ณ ์ ๋๋ค.
module.exports = {
lintRules: {
general: {
'comma-dangle': 'off',
'no-console': 'off',
'no-debugger': 'off',
},
typescript: {
'@typescript-eslint/indent': ['error', 2],
},
react: {
'react/jsx-boolean-value': 'off',
'jsx-wrap-multilines': 'off',
},
vue: {
'attribute-hyphenation': 'off',
'vue/html-closing-bracket-spacing': 'off',
'vue/html-indent': ['error', 2],
'html-self-closing': 'off',
},
unicorn: {
'escape-case': 'error',
},
},
}
Change Log
ํด๋น ํ๋ก์ ํธ์ ๋ณ๊ฒฝ์ฌํญ์ CHANGELOG.md ํ์ผ ์ฐธ์กฐ.
License
ํด๋น ํ๋ก์ ํธ์ ๋ผ์ด์ผ์ค๋ LICENSE ํ์ผ ์ฐธ์กฐ.