Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
refactor: update lint rules, auto fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Negin-Ulster committed Mar 19, 2022
1 parent 9f481c3 commit 1af2590
Show file tree
Hide file tree
Showing 36 changed files with 7,590 additions and 9,223 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = off

[*.yml]
indent_size = 2

[{CHANGELOG.md,package.json,yarn.lock}]
indent_size = false
9 changes: 9 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
website
!.eslintrc.js
node_modules
.yarn
dist
/output

**/.*
**/dist
19 changes: 19 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
root: true,
extends: ['@tophat/eslint-config/base', '@tophat/eslint-config/jest'],
rules: {
'prettier/prettier': [
'error',
{
printWidth: 100,
tabWidth: 4,
semi: false,
trailingComma: 'all' /* Reduces git diff. */,
singleQuote: true,
arrowParens: 'always', // Reduces character diff when adding Typescript types.
},
],
'@typescript-eslint/no-non-null-assertion': 'off',
'no-empty': ['error', { allowEmptyCatch: true }]
}
}
15 changes: 0 additions & 15 deletions .github/actions/lint/action.yml

This file was deleted.

28 changes: 19 additions & 9 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
CI: 1

jobs:
client:
static-analysis:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-latest
steps:
Expand All @@ -27,10 +27,24 @@ jobs:
with:
path: ./node_modules
key: ${{ env.NODE_VERSION }}-${{ hashFiles('yarn.lock') }}
- name: lint client
uses: ./.github/actions/lint
- name: Lint
run: make lint
client:
if: "!contains(github.event.head_commit.message, 'skip ci')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/detect-env
- name: Setup Node.js
uses: actions/setup-node@v3.0.0
with:
project: client
node-version: ${{ env.NODE_VERSION }}
- name: Restore node modules cache
id: node-modules-cache
uses: actions/cache@v2
with:
path: ./node_modules
key: ${{ env.NODE_VERSION }}-${{ hashFiles('yarn.lock') }}
- name: build client
uses: ./.github/actions/build
with:
Expand Down Expand Up @@ -64,10 +78,6 @@ jobs:
with:
path: ./node_modules
key: ${{ env.NODE_VERSION }}-${{ hashFiles('yarn.lock') }}
- name: lint service
uses: ./.github/actions/lint
with:
project: service
- name: build service
uses: ./.github/actions/build
with:
Expand Down Expand Up @@ -123,7 +133,7 @@ jobs:
GH_TOKEN: ${{ secrets.TOPHAT_BOT_GH_TOKEN }}
release:
if: (github.ref == 'refs/heads/master') && (!contains(github.event.head_commit.message, 'skip ci'))
needs: [service, client]
needs: [static-analysis, service, client]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand Down
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
SHELL := /bin/bash
export PATH := $(shell yarn bin):$(PATH)

ARTIFACTS_DIR = artifacts
BUILD_DIR = ${ARTIFACTS_DIR}/build
TEST_REPORTS_DIR ?= $(ARTIFACTS_DIR)/reports

.PHONY: install
install:
yarn install
Expand All @@ -25,3 +29,20 @@ create-release-package:
rm -rf release-archive
mkdir release-archive
mv client/bin/* release-archive/


ifdef CI
ESLINT_EXTRA_ARGS=--format junit --output-file $(TEST_REPORTS_DIR)/lint/eslint.junit.xml
else
ESLINT_EXTRA_ARGS=
endif

ESLINT_ARGS=--max-warnings 0 $(ESLINT_EXTRA_ARGS)

.PHONY: lint
lint:
yarn eslint $(ESLINT_ARGS) .

.PHONY: lint-fix
lint-fix:
yarn eslint $(ESLINT_ARGS) --fix .
5 changes: 0 additions & 5 deletions client/.eslintrc.yml

This file was deleted.

17 changes: 0 additions & 17 deletions client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ VERSION := $(shell cat package.json | jq -r '.version')
ARTIFACT_DIR?=artifacts
TEST_REPORTS_DIR?=$(ARTIFACT_DIR)/reports

ifdef CI
ESLINT_EXTRA_ARGS=--format junit --output-file $(TEST_REPORTS_DIR)/lint/eslint.junit.xml
else
ESLINT_EXTRA_ARGS=
endif

ESLINT_ARGS=--max-warnings 0 $(ESLINT_EXTRA_ARGS)

.PHONY: install
install:
yarn install
Expand All @@ -36,15 +28,6 @@ package:
clean:
@rm -rf node_modules


.PHONY: lint
lint:
yarn eslint $(ESLINT_ARGS) .

.PHONY: lint-fix
lint-fix:
yarn eslint $(ESLINT_ARGS) --fix .

PHONY: publish-docker
publish-docker:
@echo "Publishing Docker Image"
Expand Down
8 changes: 0 additions & 8 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,5 @@
},
"pkg": {
"scripts": "./src/*.js"
},
"devDependencies": {
"@tophat/eslint-config": "^0.1.4",
"eslint": "^5.9.0",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-jest": "^22.1.2",
"eslint-plugin-prettier": "^3.0.0",
"prettier": "^1.15.3"
}
}
43 changes: 12 additions & 31 deletions client/src/cli.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#!/usr/bin/env node
const path = require('path')

const chalk = require('chalk')
const program = require('commander')
const fs = require('fs-extra')
const glob = require('glob')
const program = require('commander')

const EXIT_CODES = require('./exit-codes')
const { collectVariables, retrieveConfigurations } = require('./utils')
const runTests = require('./run-tests')

const chalk = require('chalk')
const { collectVariables, retrieveConfigurations } = require('./utils')

const CONFIG_OPTIONS = [
'lambdaFunction',
Expand Down Expand Up @@ -62,12 +61,7 @@ program
'Enables local mode for the sanity-runner-client. Will send tests to local container instead of lambda. Used in conjuction with --containerName',
)
.option('--output-dir <directory>', 'Test results output directory.')
.option(
'--var [VAR=VALUE]',
'Custom variables passed to all jest tests.',
collectVariables,
{},
)
.option('--var [VAR=VALUE]', 'Custom variables passed to all jest tests.', collectVariables, {})
.option(
'--retry-count <retryCount>',
'Specify number of retries a test will perform if an error occurs (default 0)',
Expand All @@ -80,25 +74,14 @@ program

const baseConfiguration = {}
if (program.args.length > 0) baseConfiguration.testPathPattern = program.args[0]
const configuration = retrieveConfigurations(
program,
CONFIG_OPTIONS,
baseConfiguration,
)
const testDir = path.resolve(
process.cwd(),
configuration.testDir || DEFAULT_TEST_DIR,
)
const configuration = retrieveConfigurations(program, CONFIG_OPTIONS, baseConfiguration)
const testDir = path.resolve(process.cwd(), configuration.testDir || DEFAULT_TEST_DIR)
const testFileNames = glob.sync('**/*.js', { cwd: testDir })

console.log(`Reading test files in ${testDir}...`)

const includeRegex = configuration.include
? new RegExp(configuration.include)
: null
const excludeRegex = configuration.exclude
? new RegExp(configuration.exclude)
: null
const includeRegex = configuration.include ? new RegExp(configuration.include) : null
const excludeRegex = configuration.exclude ? new RegExp(configuration.exclude) : null

const testFiles = testFileNames.reduce((payload, filename) => {
const filePath = path.join(testDir, filename)
Expand All @@ -115,11 +98,9 @@ const testFiles = testFileNames.reduce((payload, filename) => {

if (Object.keys(testFiles).length === 0) {
if (includeRegex || excludeRegex) {
console.log(
`No test file(s) is found matching the regex supplied in your config settings.`,
)
console.log('No test file(s) is found matching the regex supplied in your config settings.')
} else {
console.log(`No test file(s) is found.`)
console.log('No test file(s) is found.')
}
process.exit(EXIT_CODES.INVALID_ARGUMENT)
}
Expand Down Expand Up @@ -150,11 +131,11 @@ runTests(
localPort,
timeout,
)
.then(function(testsPassed) {
.then(function (testsPassed) {
console.log('All test suites ran.')
process.exit(testsPassed ? EXIT_CODES : EXIT_CODES.TEST_FAILED)
})
.catch(function(err) {
.catch(function (err) {
console.log('Caught rejection')
console.log(err)
process.exit(EXIT_CODES.FATAL_ERROR)
Expand Down
Loading

0 comments on commit 1af2590

Please sign in to comment.