Skip to content

Commit

Permalink
feat: support typescript linting and type checking (#474)
Browse files Browse the repository at this point in the history
* feat: support typescript eslint

* feat: run tsc --noEmit on typescript projects

* chore: remove unused babel-eslint package
  • Loading branch information
kabaros authored Oct 22, 2024
1 parent f36c1e1 commit b68f69a
Show file tree
Hide file tree
Showing 7 changed files with 1,019 additions and 264 deletions.
2 changes: 1 addition & 1 deletion config/eslint-react.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
parser: 'babel-eslint',
parser: '@typescript-eslint/parser',

plugins: ['react-hooks'],

Expand Down
13 changes: 13 additions & 0 deletions config/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ module.exports = {
},
sourceType: 'module',
},
// Limit TypeScript linting to TS/TSX
overrides: [
{
files: ['**/*.{ts,tsx}'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:import/typescript',
],
rules: {
'import/extensions': 'off',
},
},
],

rules: {
'max-params': [
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
"@commitlint/config-conventional": "^13.1.0",
"@dhis2/cli-helpers-engine": "^3.0.0",
"@ls-lint/ls-lint": "^1.10.0",
"babel-eslint": "^10.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"@typescript-eslint/eslint-plugin": "^8.9.0",
"@typescript-eslint/parser": "^8.9.0",
"eslint": "^8",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-react": "^7.31.10",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "^5.0.0",
"fast-glob": "^3.2.5",
"find-up": "^5.0.0",
"fs-extra": "^10.0.0",
Expand All @@ -49,6 +50,7 @@
"semver": "^7.3.5",
"stylelint": "^16.3.1",
"stylelint-use-logical": "^2.1.2",
"typescript": "^5.6.3",
"yargs": "^16.2.0"
},
"publishConfig": {
Expand Down
17 changes: 16 additions & 1 deletion src/commands/types/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { exit } = require('@dhis2/cli-helpers-engine')
const { eslint } = require('../../tools/eslint.js')
const { prettier } = require('../../tools/prettier.js')
const { stylelint } = require('../../tools/stylelint.js')
const { typescriptCheck } = require('../../tools/typescript-check.js')
const { configured } = require('../../utils/config.js')
const { selectFiles } = require('../../utils/files.js')
const {
Expand Down Expand Up @@ -52,8 +53,22 @@ exports.handler = (argv, callback) => {
return
}

const isTypescriptProject = configured('typescript')

if (isTypescriptProject) {
log.info('typescript > tsc --noEmit')
typescriptCheck({ callback: finalStatus })

if (finalStatus() === 0) {
log.print('Typescript check completed successfully.')
log.print('')
}
}

if (configured('eslint')) {
log.info('javascript > eslint')
log.info(
`${isTypescriptProject ? 'typescript' : 'javascript'} > eslint`
)
eslint({
apply,
files: jsFiles,
Expand Down
8 changes: 8 additions & 0 deletions src/tools/typescript-check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { bin } = require('@dhis2/cli-helpers-engine').exec
const { PROJECT_ROOT } = require('../utils/paths.js')

exports.typescriptCheck = ({ callback }) => {
const cmd = 'tsc'

bin(cmd, { args: ['--noEmit'], PROJECT_ROOT }, callback)
}
1 change: 1 addition & 0 deletions src/utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const packageConfigs = {
* project.
*/
const projectConfigs = {
typescript: path.join(PROJECT_ROOT, 'tsconfig.json'),
editorconfig: path.join(PROJECT_ROOT, '.editorconfig'),
eslint: path.join(PROJECT_ROOT, '.eslintrc.js'),
prettier: path.join(PROJECT_ROOT, '.prettierrc.js'),
Expand Down
Loading

0 comments on commit b68f69a

Please sign in to comment.