Skip to content

Commit

Permalink
Added eslint config for blocks and added lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbtlr committed Jun 27, 2018
1 parent c645633 commit 1272ff7
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 64 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
assets/build
assets/js
node_modules
176 changes: 176 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
module.exports = {
root: true,
parser: 'babel-eslint',
extends: [
'wordpress',
'plugin:wordpress/esnext',
'plugin:react/recommended',
'plugin:jsx-a11y/recommended',
],
env: {
browser: true,
es6: true,
},
parserOptions: {
sourceType: 'module',
ecmaFeatures: {
jsx: true,
},
},
globals: {
wp: true,
window: true,
document: true,
"jQuery": true,
"ajaxurl": true,
"woo_localized_data": true
},
plugins: [
'wordpress',
'react',
'jsx-a11y',
],
settings: {
react: {
pragma: 'wp',
},
},
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' ],
'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',
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',
},
overrides: [
{
files: 'packages/**/*.js?',
settings: {
react: {
pragma: 'createElement',
},
},
},
],
};
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */

/* jshint node:true */
module.exports = function( grunt ){
module.exports = function( grunt ) {
'use strict';

grunt.initConfig({
Expand Down
1 change: 0 additions & 1 deletion assets/blocks/build/jobs.js

This file was deleted.

27 changes: 13 additions & 14 deletions assets/blocks/jobs/edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* Internal Dependencies.
*/
import { Fragment } from 'react';
import Sidebar from './sidebar.jsx';
import Types from './types.jsx';
import JobPlaceholderList from './job-placeholder-list.jsx';
Expand All @@ -22,7 +23,7 @@ class JobsEdit extends Component {
const { className, attributes, setAttributes } = this.props;

return (
<div className={ `${className}__show-filters` }>
<div className={ `${ className }__show-filters` }>
<ToggleControl
label={ __( 'Show filters on the frontend?' ) }
checked={ attributes.showFilters }
Expand All @@ -37,25 +38,25 @@ class JobsEdit extends Component {

return (
<div>
<div className={ `${className}__search-boxes` }>
<div className={ `${ className }__search-boxes` }>
<TextControl
className={ `${className}__keywords` }
className={ `${ className }__keywords` }
placeholder={ __( 'Keywords' ) }
help={ isSelected ? __( 'Default keyword search' ) : '' }
value={ attributes.keywords }
onChange={ ( keywords ) => setAttributes( { keywords } ) }
/>
<TextControl
className={ `${className}__location` }
className={ `${ className }__location` }
placeholder={ __( 'Location' ) }
help={ isSelected ? __( 'Default location search' ) : '' }
value={ attributes.location }
onChange={ ( location ) => setAttributes( { location } ) }
/>
<div className="clearfix"/>
<div className="clearfix" />
</div>
<Types
className={ `${className}__types` }
className={ `${ className }__types` }
attributes={ attributes }
setAttributes={ setAttributes }
isSelected={ isSelected }
Expand All @@ -67,25 +68,23 @@ class JobsEdit extends Component {
render() {
const { attributes, setAttributes, className, isSelected } = this.props;

return [
(
return (
<Fragment>
<div className={ className }>
{ isSelected && this.renderShowFiltersControl() }
{ ( isSelected || attributes.showFilters )
&& this.renderFilters()
{ ( isSelected || attributes.showFilters ) &&
this.renderFilters()
}
<JobPlaceholderList number={ 3 } />
</div>
),
(
<InspectorControls key="inspector">
<Sidebar
attributes={ attributes }
setAttributes={ setAttributes }
/>
</InspectorControls>
),
];
</Fragment>
);
}
}

Expand Down
6 changes: 2 additions & 4 deletions assets/blocks/jobs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import edit from './edit.jsx';
const { registerBlockType } = wp.blocks,
{ applyFilters } = wp.hooks;


/**
* Base attributes configuration for the Jobs block. Other attributes may be
* added using the `wpjm_block_jobs_attributes_config` filter.
Expand All @@ -31,7 +30,6 @@ const attributesConfig = {
},
};


/**
* Register the Jobs block.
*/
Expand Down Expand Up @@ -62,10 +60,10 @@ registerBlockType( 'wp-job-manager/jobs', {
);

const paramsString = Object.entries( shortcodeParams ).map(
( [ attr, value ] ) => `${attr}="${value}"`
( [ attr, value ] ) => `${ attr }="${ value }"`
).join( ' ' );

return `[jobs ${paramsString}]`;
return `[jobs ${ paramsString }]`;
},

} );
22 changes: 12 additions & 10 deletions assets/blocks/jobs/job-placeholder-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { __, sprintf } = wp.i18n,

/**
* JobPlaceholder component.
*
* @return {Object} The JobPlaceholder component
*/
export default function JobPlaceholderList( { number, className } ) {
const placeholders = [];
Expand All @@ -15,21 +17,21 @@ export default function JobPlaceholderList( { number, className } ) {

for ( let i = 1; i <= number; i++ ) {
placeholders.push(
<div className={ `${classPrefix}__job` }>
<div className={ `${classPrefix}__icon` }>
<div className={ `${ classPrefix }__job` }>
<div className={ `${ classPrefix }__icon` }>
<Dashicon icon="building" />
</div>
<div className={ `${classPrefix}__name` }>
{ sprintf( __( "Job %d" ), i ) }
<div className={ `${ classPrefix }__name` }>
{ sprintf( __( 'Job %d' ), i ) }
</div>
<div className={ `${classPrefix}__place` }>
{ __( "Place" ) }
<div className={ `${ classPrefix }__place` }>
{ __( 'Place' ) }
</div>
<div className={ `${classPrefix}__type-date` }>
<p className={ `${classPrefix}__type` }>
{ __( "Type" ) }
<div className={ `${ classPrefix }__type-date` }>
<p className={ `${ classPrefix }__type` }>
{ __( 'Type' ) }
</p>
<p>{ __( "Date" ) }</p>
<p>{ __( 'Date' ) }</p>
</div>
</div>
);
Expand Down
Loading

0 comments on commit 1272ff7

Please sign in to comment.