Skip to content

Commit

Permalink
Add prettier code formatter (#7274)
Browse files Browse the repository at this point in the history
* Add prettier

* Add wordpress/prettier-config

* Add prettier config

* Update @wordpress/eslint-plugin extended config to recommended

* Update code formatting with WPCS compatible prettier formatter

* Remove rules which conflicts with prettier

* Fix eslint errors after switching to prettier code formatter

* Move eslint config to a extension based file

* Update code formatting

* Update package lock file

* Update JS files formatting with prettier

* Update deps order

* Update comment body delimiter
  • Loading branch information
thelovekesh authored Dec 8, 2022
1 parent bf74d0d commit 614e495
Show file tree
Hide file tree
Showing 317 changed files with 17,281 additions and 12,065 deletions.
134 changes: 0 additions & 134 deletions .eslintrc

This file was deleted.

154 changes: 154 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
module.exports = {
root: true,
extends: [
'plugin:@wordpress/eslint-plugin/recommended',
'plugin:import/recommended',
'plugin:eslint-comments/recommended',
],
env: {
browser: true,
},
rules: {
'block-scoped-var': 'error',
complexity: ['error', { max: 20 }],
'consistent-return': 'error',
'default-case': 'error',
'guard-for-in': 'error',
'no-await-in-loop': 'error',
'no-extra-bind': 'error',
'no-extra-label': 'error',
'no-floating-decimal': 'error',
'no-implicit-coercion': 'error',
'no-implicit-globals': 'error',
'no-implied-eval': 'error',
'no-loop-func': 'error',
'no-new': 'error',
'no-new-func': 'error',
'no-new-wrappers': 'error',
'no-restricted-properties': 'error',
'no-return-assign': 'error',
'no-return-await': 'error',
'no-sequences': 'error',
'no-shadow': 'error',
'no-template-curly-in-string': 'error',
'no-throw-literal': 'error',
'no-unmodified-loop-condition': 'error',
'no-unused-vars': [
'error',
{
ignoreRestSiblings: true,
},
],
'no-useless-call': 'error',
'no-useless-concat': 'error',
'prefer-object-spread': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
radix: ['error', 'as-needed'],
'require-await': 'error',
'rest-spread-spacing': ['error', 'never'],
'react/prop-types': 'error',
'react-hooks/exhaustive-deps': [
'error',
{ additionalHooks: 'useSelect' },
],
'react/jsx-closing-tag-location': 'error',
'react/jsx-fragments': 'error',
'react/jsx-first-prop-new-line': 'error',
'react/jsx-max-props-per-line': ['error', { when: 'multiline' }],
'react/jsx-no-literals': 'error',
'react/jsx-no-useless-fragment': 'error',
'react/no-unused-prop-types': 'error',
'react/self-closing-comp': 'error',
'import/no-unresolved': [
'error',
{
ignore: [
'jquery',
'amp-block-editor-data',
'amp-settings',
'amp-themes',
'amp-plugins',
'amp-support',
'amp-block-validation',
'amp-site-scan-notice',
],
},
],
'import/order': [
'error',
{
groups: [
'builtin',
['external', 'unknown'],
'internal',
'parent',
'sibling',
'index',
],
},
],
'jsdoc/check-indentation': 'error',
'@wordpress/dependency-group': 'error',
'@wordpress/react-no-unsafe-timeout': 'error',
},
overrides: [
{
files: [
'**/__tests__/**/*.js',
'**/test/*.js',
'**/?(*.)test.js',
'tests/js/**/*.js',
],
extends: ['plugin:jest/all'],
rules: {
'jest/prefer-lowercase-title': [
'error',
{
ignore: ['describe'],
},
],
'jest/max-expects': 'off',
'jest/no-hooks': 'off',
'jest/prefer-expect-assertions': 'off',
'jest/prefer-inline-snapshots': 'off',
'jest/prefer-snapshot-hint': 'off',
},
},
{
files: ['tests/e2e/**/*.js'],
extends: [
'plugin:@wordpress/eslint-plugin/test-e2e',
'plugin:jest/all',
],
rules: {
'jest/prefer-lowercase-title': [
'error',
{
ignore: ['describe'],
},
],
'jest/max-expects': 'off',
'jest/no-hooks': 'off',
'jest/prefer-expect-assertions': 'off',
'jest/prefer-inline-snapshots': 'off',
},
},
{
files: ['assets/src/mobile-redirection.js'],
globals: {
AMP_MOBILE_REDIRECTION: false,
location: false,
navigator: false,
sessionStorage: false,
},
},
{
files: ['assets/src/customizer/amp-customize-controls.js'],
globals: {
HTMLAnchorElement: false,
},
},
],
};
8 changes: 5 additions & 3 deletions .github/workflows/build-test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,15 @@ jobs:

- name: Get comment body
id: get-comment-body
# Setting a multi-line output requires escaping line-feeds. See <https://github.community/t/set-output-truncates-multiline-strings/16852/3>.
# Setting a multi-line output requires escaping line-feeds. See <https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings>.
run: |
body="Plugin builds for ${{ github.event.pull_request.head.sha }} are ready :bellhop_bell:!
- Download [development build](https://storage.googleapis.com/ampwp_github_artifacts/${{ github.ref }}/dev/amp.zip?${{ github.sha }})
- Download [production build](https://storage.googleapis.com/ampwp_github_artifacts/${{ github.ref }}/prod/amp.zip?${{ github.sha }})"
body="${body//$'\n'/'%0A'}"
echo "body=$body" >> $GITHUB_OUTPUT
delimiter="${body//$'\n'/'%0A'}"
echo "body<<${delimiter}" >> $GITHUB_OUTPUT
echo "$body" >> $GITHUB_OUTPUT
echo "${delimiter}" >> $GITHUB_OUTPUT
- name: Create comment on PR with links to plugin builds
if: ${{ steps.find-comment.outputs.comment-id == '' }}
Expand Down
22 changes: 6 additions & 16 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
module.exports = {
"package.json": [
"npm run lint:pkg-json"
],
"**/*.(css|scss)": [
"npm run lint:css"
],
"**/*.js": [
"npm run lint:js"
],
"**/!(amp.php).php": [
"npm run lint:php"
],
"amp.php": [
"vendor/bin/phpcs --runtime-set testVersion 5.2-"
],
"*.php": () => 'composer analyze'
'package.json': ['npm run lint:pkg-json'],
'**/*.(css|scss)': ['npm run lint:css'],
'**/*.js': ['npm run lint:js'],
'**/!(amp.php).php': ['npm run lint:php'],
'amp.php': ['vendor/bin/phpcs --runtime-set testVersion 5.2-'],
'*.php': () => 'composer analyze',
};
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"@wordpress/prettier-config"
Loading

0 comments on commit 614e495

Please sign in to comment.