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

Update for latest gutenberg compatibility #23

Merged
merged 13 commits into from
Aug 13, 2018
Merged
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

node_modules
*.build.js
159 changes: 159 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
module.exports = {
Copy link
Member

Choose a reason for hiding this comment

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

This is prone to falling out of sync. Is okay for now, but we should try to push WordPress/gutenberg#7965 and update to use the single configuration.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes waiting for eslint config to be published as a package will simplify things

extends: [
'wordpress',
'plugin:wordpress/esnext',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
],
env: {
browser: false,
es6: true,
node: true,
},
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
globals: {
wp: true,
window: true,
document: true,
},
plugins: [
'wordpress',
'react',
'jsx-a11y',
],
rules: {
'array-bracket-spacing': [ 'error', 'always' ],
'arrow-parens': [ 'error', 'always' ],
'arrow-spacing': 'error',
'brace-style': [ 'error', '1tbs' ],
camelcase: [ 'error', { properties: 'never' } ],
'comma-dangle': [ 'error', 'always-multiline' ],
'comma-spacing': 'error',
'comma-style': 'error',
'computed-property-spacing': [ 'error', 'always' ],
'dot-notation': 'error',
'eol-last': 'error',
eqeqeq: 'error',
'func-call-spacing': 'error',
indent: [ 'error', 'tab', { SwitchCase: 1 } ],
'jsx-a11y/label-has-for': [ 'error', {
required: 'id',
} ],
'jsx-a11y/media-has-caption': 'off',
'jsx-a11y/no-noninteractive-tabindex': 'off',
'jsx-a11y/role-has-required-aria-props': 'off',
'jsx-quotes': 'error',
'key-spacing': 'error',
'keyword-spacing': 'error',
'lines-around-comment': 'off',
'no-alert': 'error',
'no-bitwise': 'error',
'no-caller': 'error',
'no-console': 'error',
'no-debugger': 'error',
'no-dupe-args': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-else-return': 'error',
'no-eval': 'error',
'no-extra-semi': 'error',
'no-fallthrough': 'error',
'no-lonely-if': 'error',
'no-mixed-operators': 'error',
'no-mixed-spaces-and-tabs': 'error',
'no-multiple-empty-lines': [ 'error', { max: 1 } ],
'no-multi-spaces': 'error',
'no-multi-str': 'off',
'no-negated-in-lhs': 'error',
'no-nested-ternary': 'error',
'no-redeclare': 'error',
'no-restricted-syntax': [
'error',
{
selector: 'CallExpression[callee.name=/^__|_n|_x$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=/^_n|_x$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
{
selector: 'CallExpression[callee.name=_nx]:not([arguments.2.type=/^Literal|BinaryExpression$/])',
message: 'Translate function arguments must be string literals.',
},
],
'no-shadow': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
'no-unreachable': 'error',
'no-unsafe-negation': 'error',
'no-unused-expressions': 'error',
'no-unused-vars': 'error',
'no-useless-return': 'error',
'no-whitespace-before-property': 'error',
'object-curly-spacing': [ 'error', 'always' ],
'padded-blocks': [ 'error', 'never' ],
quotes: [ 'error', 'single', { allowTemplateLiterals: true, avoidEscape: true } ],
'quote-props': [ 'error', 'as-needed' ],
'react/display-name': 'off',
'react/jsx-curly-spacing': [ 'error', {
when: 'always',
children: true,
} ],
'react/jsx-equals-spacing': 'error',
'react/jsx-indent': [ 'error', 'tab' ],
'react/jsx-indent-props': [ 'error', 'tab' ],
'react/jsx-key': 'error',
'react/jsx-tag-spacing': 'error',
'react/no-children-prop': 'off',
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
semi: 'error',
'semi-spacing': 'error',
'space-before-blocks': [ 'error', 'always' ],
'space-before-function-paren': [ 'error', {
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
} ],
'space-in-parens': [ 'error', 'always' ],
'space-infix-ops': [ 'error', { int32Hint: false } ],
'space-unary-ops': [ 'error', {
overrides: {
'!': true,
yield: true,
},
} ],
'valid-jsdoc': [ 'error', {
prefer: {
arg: 'param',
argument: 'param',
extends: 'augments',
returns: 'return',
},
preferType: {
array: 'Array',
bool: 'boolean',
Boolean: 'boolean',
float: 'number',
Float: 'number',
int: 'number',
integer: 'number',
Integer: 'number',
Number: 'number',
object: 'Object',
String: 'string',
Void: 'void',
},
requireParamDescription: false,
requireReturn: false,
} ],
'valid-typeof': 'error',
yoda: 'off',
},
};
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Directories/files that may be generated by this project
Copy link
Member

Choose a reason for hiding this comment

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

Many of these don't exist in this repository:

  • phpcs.xml
  • docker-compose.override.yml

node_modules

# Directories/files that may appear in your environment
.DS_Store
*.log
/yarn.lock
6 changes: 4 additions & 2 deletions 01-basic-esnext/block.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { __ } = wp.i18n;
const { __, setLocaleData } = wp.i18n;
const { registerBlockType } = wp.blocks;

const blockStyle = {
Expand All @@ -7,8 +7,10 @@ const blockStyle = {
padding: '20px',
};

setLocaleData( window.gutenberg_examples_01_esnext.localeData, 'gutenberg-examples' );

registerBlockType( 'gutenberg-examples/example-01-basic-esnext', {
title: __( 'Example: Basic (esnext)' ),
title: __( 'Example: Basic (esnext)', 'gutenberg-examples' ),
icon: 'universal-access-alt',
category: 'layout',
edit() {
Expand Down
47 changes: 43 additions & 4 deletions 01-basic-esnext/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,52 @@

defined( 'ABSPATH' ) || exit;

add_action( 'enqueue_block_editor_assets', 'gutenberg_examples_01_esnext_enqueue_block_editor_assets' );
/**
* Load all translations for our plugin from the MO file.
*/
add_action( 'init', 'gutenberg_examples_01_esnext_load_textdomain' );

function gutenberg_examples_01_esnext_enqueue_block_editor_assets() {
wp_enqueue_script(
function gutenberg_examples_01_esnext_load_textdomain() {
load_plugin_textdomain( 'gutenberg-examples', false, basename( __DIR__ ) . '/languages' );
}

/**
* Registers all block assets so that they can be enqueued through Gutenberg in
* the corresponding context.
*
* Passes translations to JavaScript.
*/
function gutenberg_examples_01_esnext_register_block() {

if ( ! function_exists( 'register_block_type' ) ) {
// Gutenberg is not active.
return;
}

wp_register_script(
'gutenberg-examples-01-esnext',
plugins_url( 'block.build.js', __FILE__ ),
array( 'wp-blocks', 'wp-i18n', 'wp-element' ),
filemtime( plugin_dir_path( __FILE__ ) . 'block.build.js' )
);
}

register_block_type( 'gutenberg-examples/example-01-basic-esnext', array(
'script' => 'gutenberg-examples-01-esnext',
) );

/*
* Pass already loaded translations to our JavaScript.
*
* This happens _before_ our JavaScript runs, afterwards it's too late.
*/
wp_add_inline_script(
'gutenberg-examples-01-esnext',
sprintf(
'var gutenberg_examples_01_esnext = { localeData: %s };',
json_encode( gutenberg_get_jed_locale_data( 'gutenberg-examples' ) )
),
'before'
);

}
add_action( 'init', 'gutenberg_examples_01_esnext_register_block' );
Empty file.
Loading