Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint and ci #1

Merged
merged 8 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 137 additions & 9 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,156 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
ignorePatterns: ['dist', '.eslintrc.cjs'],

parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},

plugins: [
'react',
'react-hooks',
'react-refresh',
'import',
'flowtype',
'jsx-a11y',
// 'jest',
// 'testing-library',

],
extends: [
'eslint:recommended',
// 'plugin:@typescript-eslint/recommended-type-checked',
// 'plugin:@typescript-eslint/recommended-type-checked', // less strict
'plugin:@typescript-eslint/strict-type-checked',
'plugin:@typescript-eslint/stylistic-type-checked',
'plugin:react-hooks/recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
settings: {
"react": { "version": "detect"}
},
plugins: ['react-refresh'],

rules: {
"eqeqeq": ["error"],

// Default exports allow renaming on import, which can lead to confusing
// code. IMO, we should ban them. Do we need to upgrade eslint or
// something?
// "no-default-export": ["warn"],

// migrated from:
// https://github.com/facebook/create-react-app/blob/0a827f69ab0d2ee3871ba9b71350031d8a81b7ae/packages/eslint-config-react-app/index.js
/// TypeScript's `noFallthroughCasesInSwitch` option is more robust (#6906)
'default-case': 'off',
/// 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/291)
// 'no-dupe-class-members': 'off',
/// 'tsc' already handles this (https://github.com/typescript-eslint/typescript-eslint/issues/477)
// 'no-undef': 'off',

// react
////////
"react/function-component-definition": [
"error",
{
"namedComponents": "arrow-function",
"unnamedComponents": "arrow-function",
},
],

// migrated from:
// https://github.com/facebook/create-react-app/blob/0a827f69ab0d2ee3871ba9b71350031d8a81b7ae/packages/eslint-config-react-app/base.js
'react/jsx-uses-vars': 'error',
'react/jsx-uses-react': 'warn',

'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],

// typescript
/////////////
"@typescript-eslint/ban-ts-comment": [
"warn",
{
"ts-ignore": "allow-with-description",
},
],

/// Add TypeScript specific rules (and turn off ESLint equivalents)
// '@typescript-eslint/consistent-type-assertions': 'warn', // defaults to "error"
'no-array-constructor': 'off',
// '@typescript-eslint/no-array-constructor': 'warn', // default to "error"
'no-redeclare': 'off',
'@typescript-eslint/no-redeclare': 'error',
'no-use-before-define': 'off',
'@typescript-eslint/no-use-before-define': [
'warn',
{
functions: false,
classes: false,
variables: false,
typedefs: false,
},
],
'no-unused-expressions': 'off',
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
},
],
'no-unused-vars': 'off',
// '@typescript-eslint/no-unused-vars': [
// 'warn',
// {
// args: 'none',
// ignoreRestSiblings: true,
// },
// ], // default "error"
'no-useless-constructor': 'off',
// '@typescript-eslint/no-useless-constructor': 'warn', // default "error"

/*
// migrated from:
// https://github.com/facebook/create-react-app/blob/0a827f69ab0d2ee3871ba9b71350031d8a81b7ae/packages/eslint-config-react-app/jest.js
/// https://github.com/jest-community/eslint-plugin-jest
'jest/no-conditional-expect': 'error',
'jest/no-identical-title': 'error',
'jest/no-interpolation-in-snapshots': 'error',
'jest/no-jasmine-globals': 'error',
'jest/no-mocks-import': 'error',
'jest/valid-describe-callback': 'error',
'jest/valid-expect': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/valid-title': 'warn',

/// https://github.com/testing-library/eslint-plugin-testing-library
'testing-library/await-async-queries': 'error',
'testing-library/await-async-utils': 'error',
'testing-library/no-await-sync-queries': 'error',
'testing-library/no-container': 'error',
'testing-library/no-debugging-utils': 'error',
'testing-library/no-dom-import': ['error', 'react'],
'testing-library/no-node-access': 'error',
'testing-library/no-promise-in-fire-event': 'error',
'testing-library/no-render-in-lifecycle': 'error',
'testing-library/no-unnecessary-act': 'error',
'testing-library/no-wait-for-multiple-assertions': 'error',
'testing-library/no-wait-for-side-effects': 'error',
'testing-library/no-wait-for-snapshot': 'error',
'testing-library/prefer-find-by': 'error',
'testing-library/prefer-presence-queries': 'error',
'testing-library/prefer-query-by-disappearance': 'error',
'testing-library/prefer-screen-queries': 'error',
'testing-library/render-result-naming-convention': 'error',
// end migrated config
*/
},
}
51 changes: 51 additions & 0 deletions .github/workflows/build-and-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Publish container image"

on:
push:
branches:
- "main"
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"


jobs:

test:
uses: "./.github/workflows/ci.yml"

# When a push to the default branch occurs, build and release "latest" images
# When a tag `vX.Y.Z` push occurs, build and release images with that tag
build-and-publish-image:
name: "Build and publish container image"
needs:
- "test"
uses: "nsidc/.github/.github/workflows/build-and-publish-container-image.yml@main"
secrets: "inherit"

publish-to-npmjs:
name: "Build & publish"
if: "startsWith(github.ref, 'refs/tags/v')"
needs:
- "test"
runs-on: "ubuntu-latest"
steps:

- name: "Check out repository"
uses: "actions/checkout@v4"

- name: "Setup NodeJS"
uses: "actions/setup-node@v4"
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"

- name: "Install dependencies"
run: "npm clean-install"

- name: "Build"
run: "npm run build"

- name: "Publish to npmjs.com"
run: "npm publish --access public"
env:
NODE_AUTH_TOKEN: "${{secrets.NPM_DEPLOY_TOKEN}}"
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Continuous Integration

on:
workflow_dispatch:
# Enable running this workflow from the container build workflow:
workflow_call:
pull_request:
# NOTE: The tests will be run on the main branch as part of the container build workflow.
# push:
# branches:
# - main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
# Many color libraries just need this to be set to any value, but at least
# one distinguishes color depth, where "3" -> "256-bit color".
FORCE_COLOR: 3


jobs:
checks:
name: "Check"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node_version: 22
cache: npm

- name: Install dependencies
run: npm clean-install

- name: Lint
run: npm run lint

- name: Upload coverage
uses: codecov/codecov-action@v4
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm run lint
Loading
Loading