Skip to content

Commit

Permalink
Add prettier to autoformat source, docs, and config (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcous authored Mar 22, 2023
1 parent 5d70d12 commit 2669321
Show file tree
Hide file tree
Showing 139 changed files with 4,535 additions and 3,373 deletions.
86 changes: 33 additions & 53 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
customElement: true,
},
},
}
},
],
extends: [
'eslint:recommended',
Expand All @@ -44,61 +44,34 @@ module.exports = {
'plugin:sonarjs/recommended',
'plugin:tailwindcss/recommended',
'plugin:storybook/recommended',
'prettier',
],
rules: {
// Eslint rules
'@typescript-eslint/indent': ['error', 2],
'array-bracket-spacing': 'error',
'array-callback-return': 'error',
'arrow-spacing': 'error',
'block-spacing': 'error',
'brace-style': 'error',
'comma-dangle': ['error', {
arrays: 'always-multiline',
objects: 'always-multiline',
imports: 'always-multiline',
exports: 'never',
functions: 'never',
}],
'comma-spacing': 'error',
'computed-property-spacing': 'error',
'dot-notation': 'error',
'eol-last': 'error',
eqeqeq: ['error', 'always', {
null: 'always',
}],
'func-call-spacing': 'error',
'key-spacing': 'error',
'keyword-spacing': 'error',
eqeqeq: [
'error',
'always',
{
null: 'always',
},
],
'no-caller': 'error',
'no-multi-spaces': 'error',
// https://github.com/sveltejs/eslint-plugin-svelte3/issues/41
'no-multiple-empty-lines': 'off',
'no-multi-spaces': 'error',
'no-param-reassign': 'error',
'no-return-await': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-optional-chaining': 'error',
'nonblock-statement-body-position': 'error',
'object-curly-spacing': ['error', 'always'],
'one-var': ['error', {
let: 'never',
const: 'never',
}],
quotes: ['error', 'single', {
avoidEscape: true,
}],
'one-var': [
'error',
{
let: 'never',
const: 'never',
},
],
'require-atomic-updates': 'error',
'rest-spread-spacing': 'error',
semi: ['error', 'always'],
'semi-spacing': 'error',
'semi-style': 'error',
'space-before-blocks': 'error',
'space-in-parens': 'error',
'space-infix-ops': 'error',
'space-unary-ops': 'error',
'spaced-comment': 'error',
'template-curly-spacing': 'error',
radix: 'error',
'require-await': 'error',
strict: 'error',
Expand All @@ -109,11 +82,14 @@ module.exports = {
'prefer-const': 'error',
'prefer-template': 'error',
'require-await': 'error',
'prefer-arrow/prefer-arrow-functions': ['error', {
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false,
}],
'prefer-arrow/prefer-arrow-functions': [
'error',
{
disallowPrototype: true,
singleReturnOnly: false,
classPropertiesAllowed: false,
},
],
// Unicorn rules
'unicorn/switch-case-braces': 'off',
'unicorn/no-unsafe-regex': 'error',
Expand Down Expand Up @@ -158,9 +134,13 @@ module.exports = {
'import/no-cycle': 'error',
'import/no-useless-path-segments': 'error',
'import/export': 'error',
'import/extensions': ["error", "never", {
"svelte": "always"
}],
'import/extensions': [
'error',
'never',
{
svelte: 'always',
},
],
// Do not currently work with eslint-plugin-svelte
'import/first': 'off',
'import/order': 'error',
Expand All @@ -179,9 +159,9 @@ module.exports = {
// always try to resolve types under `<root>@types` directory even it doesn't contain any source code, like `@types/unist`
alwaysTryTypes: true,
project: './tsconfig.json',
}
},
},
'svelte3/typescript': () => require('typescript'),
},
ignorePatterns: ['**/cypress/**', '**/node_modules/**', '*.json'],
};
};
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:
- name: Publish 🚀
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
token: ${{ secrets.NPM_TOKEN }}
61 changes: 31 additions & 30 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,43 @@ jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install 🔧
run: npm ci --audit=false
- name: Run ESLint
run: npm run lint
- uses: actions/checkout@v2
- name: Install 🔧
run: npm ci --audit=false
- name: Run ESLint and Prettier
run: |
npm run lint
npm run format-check

check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install 🔧
run: npm ci --audit=false
- name: Run Check
run: npm run check
- uses: actions/checkout@v2
- name: Install 🔧
run: npm ci --audit=false
- name: Run Check
run: npm run check

test:
timeout-minutes: 10
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install deps
run: |
npm ci --audit=false
cd playground
npm ci --audit=false
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Install deps
run: |
npm ci --audit=false
cd playground
npm ci --audit=false
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package-lock.json
dist
prime
8 changes: 8 additions & 0 deletions .prettierrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
plugins: ['prettier-plugin-svelte'],
singleQuote: true,
// TODO(mc, 2023-03-22): eslint-plugin-svelte does not respect single-quote for HTML
// https://github.com/sveltejs/prettier-plugin-svelte/issues/253
jsxSingleQuote: true,
svelteIndentScriptAndStyle: false,
};
6 changes: 3 additions & 3 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export default {
},
async viteFinal(config) {
return mergeConfig(config, {
base: '/'
base: '/',
});
},
framework: {
name: '@storybook/html-vite',
options: {}
options: {},
},
features: {
modernInlineRender: true,
storyStoreV7: true,
},
};
};
6 changes: 3 additions & 3 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { addons } from '@storybook/addons'
import theme from './theme'
import { addons } from '@storybook/addons';
import theme from './theme';

addons.setConfig({
theme,
enableShortcuts: false,
})
});
8 changes: 4 additions & 4 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
expanded: true,
matchers: {
Expand All @@ -9,8 +9,8 @@ export const parameters = {
},
docs: {
source: {
state: 'open'
}
state: 'open',
},
},
inlineStories: true,
}
};
4 changes: 2 additions & 2 deletions .storybook/theme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { create } from '@storybook/theming'
import { create } from '@storybook/theming';

export default create({
brandImage: 'https://www.viam.com/static/logo.svg',
fontBase: '"Space mono", sans-serif',
appBg: '#333',
})
});
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"csstools.postcss",
"bradlc.vscode-tailwindcss",
"svelte.svelte-vscode",
"silvenon.mdx"
"unifiedjs.vscode-mdx",
"esbenp.prettier-vscode"
]
}
38 changes: 38 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,41 @@ More detailed docs exist on [the storybook](https://www.viam.com/prime).
Linked below are some articles that provide knowledge for how to best build reusable, generic web components.

- [Custom Elements Best Practices](https://web.dev/custom-elements-best-practices/)

## Development tasks

To verify that static assets build correctly:

```shell
npm run build-storybook
```

To run tests locally, you must first install the `playground` development dependencies and playwright. From there, you can run tests

```shell
# set up playground
cd playground
npm install
cd ..
npx playwright install --with-deps

# run tests, with optional debugging
npm run test
npm run test-dev
```

You can typecheck and lint using:

```shell
# check types, a11y, and other component quality
npm run check

# autoformat code and documentation
npm run format

# check formatting without writing files
npm run format-check

# lint for stylistic and correctness issues
npm run lint
```
Loading

0 comments on commit 2669321

Please sign in to comment.