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

chore(lint): add linting and formatting to CI #3816

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ jobs:
name: Flow
command: yarn --cwd /buie flow check

typescript:
executor: default
steps:
- checkout
- setup-workspace
- run:
name: Typescript
command: yarn --cwd /buie tsc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is intended and related to the caching issue from a few weeks ago but the working directory defined at the top is ~/buie while all of these are commands occur at /buie

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its intentional, I tried different combinations to get it to match without having to hardcode the working directory folder, this was the only combination that worked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't these referring to separate directories though?


build-unit-tests:
executor: default
steps:
Expand Down Expand Up @@ -137,6 +146,9 @@ workflows:
- flow:
requires:
- setup
- typescript:
requires:
- setup
- build-unit-tests:
requires:
- setup
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ To test the Box UI Elements with your own project use local Yarn linking.
- `yarn start:npm` to symlink Elements via `yarn link` to a parent project.
- `yarn start:dev` to launch a local webpack dev server. Uses your own data for Elements.
- `yarn lint` to lint js and css.
- `yarn lint:js --fix` to lint js and fix issues.
- `yarn lint:css --fix` to lint styles and fix issues.
- `yarn lint:code --fix` to lint js, ts and fix issues.
- `yarn lint:styles --fix` to lint styles and fix issues.
- `yarn test` to launch tests with jest.
- `yarn test --watch` to launch tests with jest in watch mode.
- `yarn test --coverage` to launch tests with jest with coverage.
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@
"cy:open": "yarn cy:wait; yarn cypress open",
"cy:run": "yarn cy:wait; yarn cypress run --spec \"test/integration/**/*.cy.js\"",
"cy:wait": "wait-on http-get://127.0.0.1:6060/#",
"lint": "npm-run-all lint:*",
"lint:js": "eslint --max-warnings=0 .",
"lint": "npm-run-all lint:ts lint:ci",
"lint:ts": "tsc",
"lint:css": "stylelint \"src/**/*.scss\" --syntax scss",
"lint:code": "./scripts/lint-code.sh",
"lint:css": "./scripts/lint-styles.sh",
"lint:misc": "./scripts/lint-misc.sh",
"lint:ci": "./scripts/lint-all.sh",
"prebuild:es": "npm-run-all copy:styles ts:defs copy:flow",
"release": "yarn release:beta",
"release:beta": "DIST=beta BRANCH=master ./scripts/release.sh",
Expand Down
14 changes: 14 additions & 0 deletions scripts/lint-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

lint_all(){
local fix_flag=$1
local exit_code=0

./scripts/lint-code.sh $fix_flag || exit_code=$?
./scripts/lint-styles.sh $fix_flag || exit_code=$?
./scripts/lint-misc.sh $fix_flag || exit_code=$?

return $exit_code
};

lint_all $1
28 changes: 28 additions & 0 deletions scripts/lint-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

lint_code(){
local fix_flag=$1
local eslint_cmd="eslint --max-warnings 0"
local prettier_cmd="prettier --check"
local exit_code=0
local color="\033[1;34m"
local no_color="\033[0m"

if [ "$fix_flag" == "--fix" ]; then
eslint_cmd="eslint --fix --max-warnings 0"
prettier_cmd="prettier --write"
fi

echo -e "${color}Running: $prettier_cmd --parser=flow src/**/*.js${no_color}"
$prettier_cmd --parser=flow "src/**/*.js" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $prettier_cmd --parser=typescript src/**/*.{ts,tsx}${no_color}"
$prettier_cmd --parser=typescript "src/**/*.{ts,tsx}" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $eslint_cmd src/**/*.{js,ts,tsx}${no_color}"
$eslint_cmd "src/**/*.{js,ts,tsx}" || exit_code=$?

return $exit_code
};

lint_code $1
26 changes: 26 additions & 0 deletions scripts/lint-misc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

lint_misc(){
local fix_flag=$1
local prettier_cmd="prettier --check"
local exit_code=0
local color="\033[1;34m"
local no_color="\033[0m"

if [ "$fix_flag" == "--fix" ]; then
prettier_cmd="prettier --write"
fi

echo -e "${color}Running: $prettier_cmd --parser=markdown ./**/*.md${no_color}"
$prettier_cmd --parser=markdown "./**/*.md" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $prettier_cmd --parser=json ./**/*.json${no_color}"
$prettier_cmd --parser=json "./**/*.json" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $prettier_cmd --parser=html ./**/*.html${no_color}"
$prettier_cmd --parser=html "./**/*.html" --ignore-path .gitignore || exit_code=$?

return $exit_code
};

lint_misc $1
31 changes: 31 additions & 0 deletions scripts/lint-styles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

lint_styles(){
local fix_flag=$1
local stylelint_cmd="stylelint --max-warnings 0"
local prettier_cmd="prettier --check"
local exit_code=0
local color="\033[1;34m"
local no_color="\033[0m"

if [ "$fix_flag" == "--fix" ]; then
stylelint_cmd="stylelint --fix --max-warnings 0"
prettier_cmd="prettier --write"
fi

echo -e "${color}Running: $prettier_cmd --parser=scss src/**/*.scss${no_color}"
$prettier_cmd --parser=scss "src/**/*.scss" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $stylelint_cmd --syntax scss '**/*.scss'${no_color}"
$stylelint_cmd --syntax scss "**/*.scss" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $prettier_cmd --parser=css ./**/*.css${no_color}"
$prettier_cmd --parser=css "./**/*.css" --ignore-path .gitignore || exit_code=$?

echo -e "${color}Running: $stylelint_cmd --syntax css '**/*.css'${no_color}"
$stylelint_cmd --syntax css "**/*.css" --ignore-path .gitignore || exit_code=$?

return $exit_code
};

lint_styles $1
10 changes: 10 additions & 0 deletions src/elements/content-preview/ContentPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,16 @@ class ContentPreview extends React.PureComponent<Props, State> {
skipServerUpdate: true,
useHotkeys: false,
};










const { Preview } = global.Box;
this.preview = new Preview();
this.preview.addListener('load', this.onPreviewLoad);
Expand Down
Loading