Skip to content

Commit

Permalink
feat!: start migrating to typescript (#52)
Browse files Browse the repository at this point in the history
* init ts && remove commitlint

* skip any lint

* delete dist files

* fix: merge conflicts

* fix: do not build test files

* fix: linters

* fix: update node version

* fix: build before publish

* fix: ci

* fix: tests

* fix: tests

* fix: ci

* feat: add reties to vitest

* remove eslint ignore

* remove deprecated from husky

* remove eslint ignore

* remove commitlint
  • Loading branch information
fwuensche authored Sep 9, 2024
1 parent becc5ff commit c6833a4
Show file tree
Hide file tree
Showing 28 changed files with 3,172 additions and 3,761 deletions.
Empty file removed .eslintignore
Empty file.
24 changes: 21 additions & 3 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
module.exports = {
ignorePatterns: ['dist/', 'node_modules/'],
env: {
node: true,
es2021: true,
},
extends: ['eslint:recommended', 'prettier'],
overrides: [],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
rules: {},
plugins: ['@typescript-eslint'],
extends: ['eslint:recommended', 'prettier', 'plugin:@typescript-eslint/recommended'],
root: true,
overrides: [],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
// We need to ignore unused variables that start with an underscore to avoid linting errors on catch(error) blocks
{
args: 'all',
argsIgnorePattern: '^_',
caughtErrors: 'all',
caughtErrorsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
ignoreRestSiblings: true,
},
],
},
}
2 changes: 1 addition & 1 deletion .github/workflows/cherry_diff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
- name: Raise if new JavaScript code is added
# This command will fail if the number of lines of code in JavaScript files has increased
# in the current branch compared to the base branch, encouraging developers to contribute to migrating to TS.
run: ./bin/cherry.js diff --metric='TODO' --error-if-increase --quiet
run: npm run cherry -- diff --metric='TODO' --error-if-increase --quiet
2 changes: 1 addition & 1 deletion .github/workflows/cherry_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ jobs:
run: npm install

- name: Push metrics
run: ./bin/cherry.js push --quiet --api-key=${{ secrets.CHERRY_API_KEY }}
run: npm run cherry -- push --quiet --api-key=${{ secrets.CHERRY_API_KEY }}
3 changes: 3 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
- run: npm ci
if: ${{ steps.release.outputs.release_created }}

- run: npm run build
if: ${{ steps.release.outputs.release_created }}

# Make sure that the NPM_TOKEN has been set as a "Repository secret"
- run: npm publish
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ node_modules
latest.dump
results.json

# TypeScript files
dist/

# Ignore test fixtures
test/fixtures/fake-remote
test/fixtures/project-one
4 changes: 0 additions & 4 deletions .husky/commit-msg

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged

# TODO: it'd be nice to run tests here, but it does not work because cherry diff requires the git diff to be clean.
Expand Down
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# ignore everything
*

# include these
!dist/
!package.json
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.7.0
v20.14.0
12 changes: 6 additions & 6 deletions bin/cherry.js → bin/cherry.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#! /usr/bin/env node

import { program } from 'commander'
import dotenv from 'dotenv'
import { setVerboseMode } from '../src/log.js'
import diffCommand from './commands/diff.js'
import runCommand from './commands/run.js'
import backfillCommand from './commands/backfill.js'
import pushCommand from './commands/push.js'
import diffCommand from './commands/diff.js'
import dotenv from 'dotenv'
import initCommand from './commands/init.js'
import { program } from 'commander'
import pushCommand from './commands/push.js'
import runCommand from './commands/run.js'
import { setVerboseMode } from '../src/log.js'

// Do not load environment variables on tests
if (process.env.NODE_ENV !== 'test') dotenv.config()
Expand Down
5 changes: 1 addition & 4 deletions bin/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import Spinnies from 'spinnies'
import _ from 'lodash'
import axios from 'axios'
import { buildRepoURL } from '../src/permalink.js'
import fs from 'fs'
import { panic } from '../src/error.js'
import { v4 } from 'uuid'

Expand All @@ -12,8 +11,6 @@ export const API_BASE_URL = process.env.API_URL ?? 'https://www.cherrypush.com/a

export const UPLOAD_BATCH_SIZE = 1000

export const packageJson = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)))

export const countByMetric = (occurrences) =>
_(occurrences)
.groupBy('metricName')
Expand Down Expand Up @@ -160,7 +157,7 @@ export const buildSarifPayload = (projectName, branch, sha, occurrences) => {
tool: {
driver: {
name: 'cherry',
version: packageJson.version,
version: process.env.npm_package_version,
informationUri: 'https://github.com/cherrypush/cherrypush.com',
rules,
},
Expand Down
1 change: 0 additions & 1 deletion commitlint.config.cjs

This file was deleted.

Loading

0 comments on commit c6833a4

Please sign in to comment.