Fix eslint rule no-var

This commit is contained in:
Pavel Dohnal
2017-07-11 14:15:35 +01:00
parent 7a2aaa86cf
commit ca5a5301a8
24 changed files with 111 additions and 110 deletions

View File

@ -89,7 +89,6 @@
"one-var-declaration-per-line": 0,
"no-script-url": 0,
"wrap-iife": 0,
"no-var": 0,
"vars-on-top": 0,
"space-infix-ops": 0,
"no-irregular-whitespace": 0,

View File

@ -18,16 +18,16 @@ define([
FormFieldSelection,
FormFieldDate
) => {
var FormField = React.createClass({
const FormField = React.createClass({
renderField: function (data, inline = false) {
var description = false;
let description = false;
if(data.field.description) {
description = (
<p className="description">{ data.field.description }</p>
);
}
var field = false;
let field = false;
if(data.field['field'] !== undefined) {
data.field = jQuery.merge(data.field, data.field.field);
@ -84,7 +84,7 @@ define([
}
},
render: function () {
var field = false;
let field = false;
if(this.props.field['fields'] !== undefined) {
field = this.props.field.fields.map((subfield, index) => {
@ -99,7 +99,7 @@ define([
field = this.renderField(this.props);
}
var tip = false;
let tip = false;
if(this.props.field.tip) {
tip = (
<p className="description">{ this.props.field.tip }</p>

View File

@ -9,7 +9,7 @@ define([
ReactDOM,
jQuery
) => {
var Selection = React.createClass({
const Selection = React.createClass({
getInitialState: function () {
return {
items: [],
@ -55,7 +55,7 @@ define([
return;
}
var select2 = jQuery('#'+this.refs.select.id).select2({
const select2 = jQuery('#'+this.refs.select.id).select2({
width: (this.props.width || ''),
templateResult: function (item) {
if(item.element && item.element.selected) {
@ -70,7 +70,7 @@ define([
}
});
var hasRemoved = false;
let hasRemoved = false;
select2.on('select2:unselecting', () => {
hasRemoved = true;
});
@ -103,7 +103,7 @@ define([
},
loadCachedItems: function () {
if(typeof(window['mailpoet_'+this.props.field.endpoint]) !== 'undefined') {
var items = window['mailpoet_'+this.props.field.endpoint];
let items = window['mailpoet_'+this.props.field.endpoint];
if(this.props.field['filter'] !== undefined) {
@ -122,7 +122,7 @@ define([
} else {
value = e.target.value;
}
var transformedValue = this.transformChangedValue(value);
const transformedValue = this.transformChangedValue(value);
this.props.onValueChange({
target: {
value: transformedValue,

View File

@ -4,7 +4,7 @@ define([
(
React
) => {
var FormFieldTextarea = React.createClass({
const FormFieldTextarea = React.createClass({
render: function () {
return (
<textarea

View File

@ -14,7 +14,7 @@ define(
FormField
) => {
var Form = React.createClass({
const Form = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},
@ -97,7 +97,7 @@ define(
this.setState({ loading: true });
// only get values from displayed fields
var item = {};
const item = {};
this.props.fields.map((field) => {
if(field['fields'] !== undefined) {
field.fields.map((subfield) => {
@ -141,8 +141,8 @@ define(
if (this.props.onChange) {
return this.props.onChange(e);
} else {
var item = this.state.item,
field = e.target.name;
const item = this.state.item;
const field = e.target.name;
item[field] = e.target.value;
@ -153,8 +153,9 @@ define(
}
},
render: function () {
let errors;
if(this.getErrors() !== undefined) {
var errors = this.getErrors().map((error, index) => {
errors = this.getErrors().map((error, index) => {
return (
<p key={ 'error-'+index } className="mailpoet_error">
{ error.message }
@ -163,13 +164,13 @@ define(
});
}
var formClasses = classNames(
const formClasses = classNames(
'mailpoet_form',
{ 'mailpoet_form_loading': this.state.loading || this.props.loading }
);
var beforeFormContent = false;
var afterFormContent = false;
let beforeFormContent = false;
let afterFormContent = false;
if (this.props.beforeFormContent !== undefined) {
beforeFormContent = this.props.beforeFormContent(this.getValues());
@ -179,7 +180,7 @@ define(
afterFormContent = this.props.afterFormContent(this.getValues());
}
var fields = this.props.fields.map((field, i) => {
const fields = this.props.fields.map((field, i) => {
return (
<FormField
field={ field }
@ -189,7 +190,7 @@ define(
);
});
var actions = false;
let actions = false;
if(this.props.children) {
actions = this.props.children;
} else {

View File

@ -6,7 +6,7 @@ define([
React,
MailPoet
) => {
var ListingBulkActions = React.createClass({
const ListingBulkActions = React.createClass({
getInitialState: function () {
return {
action: false,
@ -18,7 +18,7 @@ define([
action: e.target.value,
extra: false
}, () => {
var action = this.getSelectedAction();
const action = this.getSelectedAction();
// action on select callback
if(action !== null && action['onSelect'] !== undefined) {
@ -31,23 +31,23 @@ define([
handleApplyAction: function (e) {
e.preventDefault();
var action = this.getSelectedAction();
const action = this.getSelectedAction();
if(action === null) {
return;
}
var selected_ids = (this.props.selection !== 'all')
const selected_ids = (this.props.selection !== 'all')
? this.props.selected_ids
: [];
var data = (action['getData'] !== undefined)
const data = (action['getData'] !== undefined)
? action.getData()
: {};
data.action = this.state.action;
var onSuccess = function () {};
let onSuccess = function () {};
if(action['onSuccess'] !== undefined) {
onSuccess = action.onSuccess;
}
@ -65,9 +65,9 @@ define([
});
},
getSelectedAction: function () {
var selected_action = this.refs.action.value;
const selected_action = this.refs.action.value;
if(selected_action.length > 0) {
var action = this.props.bulk_actions.filter((action) => {
const action = this.props.bulk_actions.filter((action) => {
return (action.name === selected_action);
});

View File

@ -8,7 +8,7 @@ define([
jQuery,
MailPoet
) => {
var ListingFilters = React.createClass({
const ListingFilters = React.createClass({
handleFilterAction: function () {
const filters = {};
this.getAvailableFilters().map((filter, i) => {

View File

@ -1,16 +1,16 @@
define(['react', 'classnames'], (React, classNames) => {
var ListingGroups = React.createClass({
const ListingGroups = React.createClass({
handleSelect: function (group) {
return this.props.onSelectGroup(group);
},
render: function () {
var groups = this.props.groups.map((group, index) => {
const groups = this.props.groups.map((group, index) => {
if(group.name === 'trash' && group.count === 0) {
return false;
}
var classes = classNames(
const classes = classNames(
{ 'current' : (group.name === this.props.group) }
);

View File

@ -38,7 +38,7 @@ const ListingItem = React.createClass({
this.setState({ expanded: !this.state.expanded });
},
render: function () {
var checkbox = false;
let checkbox = false;
if (this.props.is_selectable === true) {
checkbox = (
@ -608,7 +608,7 @@ const Listing = React.createClass({
this.setState({ loading: true });
var data = params || {};
const data = params || {};
data.listing = {
params: this.getParams(),
offset: 0,
@ -656,7 +656,7 @@ const Listing = React.createClass({
});
},
handleSelectItem: function (id, is_checked) {
var selected_ids = this.state.selected_ids,
let selected_ids = this.state.selected_ids,
selection = false;
if (is_checked) {
@ -680,7 +680,7 @@ const Listing = React.createClass({
if (is_checked === false) {
this.clearSelection();
} else {
var selected_ids = this.state.items.map((item) => {
const selected_ids = this.state.items.map((item) => {
return ~~item.id;
});

View File

@ -8,7 +8,7 @@ define([
MailPoet
) => {
var ListingPages = React.createClass({
const ListingPages = React.createClass({
getInitialState: function () {
return {
page: null
@ -60,17 +60,17 @@ define([
if(this.props.count === 0) {
return false;
} else {
var pagination = false;
var firstPage = (
let pagination = false;
let firstPage = (
<span aria-hidden="true" className="tablenav-pages-navspan">«</span>
);
var previousPage = (
let previousPage = (
<span aria-hidden="true" className="tablenav-pages-navspan"></span>
);
var nextPage = (
let nextPage = (
<span aria-hidden="true" className="tablenav-pages-navspan"></span>
);
var lastPage = (
let lastPage = (
<span aria-hidden="true" className="tablenav-pages-navspan">»</span>
);
@ -159,12 +159,12 @@ define([
);
}
var classes = classNames(
const classes = classNames(
'tablenav-pages',
{ 'one-page': (this.props.count <= this.props.limit) }
);
var numberOfItemsLabel;
let numberOfItemsLabel;
if (this.props.count == 1) {
numberOfItemsLabel = MailPoet.I18n.t('numberOfItemsSingular');
} else {

View File

@ -6,7 +6,7 @@ define([
React
) => {
var ListingSearch = React.createClass({
const ListingSearch = React.createClass({
handleSearch: function (e) {
e.preventDefault();
this.props.onSearch(

View File

@ -51,7 +51,7 @@ const stats = {
class StatsBadge extends React.Component {
getBadgeType(stat, rate) {
const len = stat.badgeRanges.length;
for (var i = 0; i < len; i += 1) {
for (let i = 0; i < len; i += 1) {
if (rate > stat.badgeRanges[i]) {
return stat.badgeTypes[i];
}

View File

@ -11,9 +11,9 @@ define(
classNames,
MailPoet
) => {
var Link = Router.Link;
const Link = Router.Link;
var Breadcrumb = React.createClass({
const Breadcrumb = React.createClass({
getInitialState: function () {
return {
step: null,
@ -39,12 +39,12 @@ define(
};
},
render: function () {
var steps = this.state.steps.map((step, index) => {
var stepClasses = classNames(
const steps = this.state.steps.map((step, index) => {
const stepClasses = classNames(
{ 'mailpoet_current': (this.props.step === step.name) }
);
var label = step.label;
let label = step.label;
if(step['link'] !== undefined && this.props.step !== step.name) {
label = (

View File

@ -22,7 +22,7 @@ define(
Breadcrumb
) => {
var NewsletterSend = React.createClass({
const NewsletterSend = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},
@ -34,11 +34,11 @@ define(
};
},
getFieldsByNewsletter: function (newsletter) {
var type = this.getSubtype(newsletter);
const type = this.getSubtype(newsletter);
return type.getFields(newsletter);
},
getSendButtonOptions: function () {
var type = this.getSubtype(this.state.item);
const type = this.getSubtype(this.state.item);
return type.getSendButtonOptions(this.state.item);
},
getSubtype: function (newsletter) {
@ -162,7 +162,7 @@ define(
},
handleRedirectToDesign: function (e) {
e.preventDefault();
var redirectTo = e.target.href;
const redirectTo = e.target.href;
this._save(e).done(() => {
MailPoet.Notice.success(
@ -173,7 +173,7 @@ define(
}).fail(this._showError);
},
_save: function () {
var data = this.state.item;
const data = this.state.item;
this.setState({ loading: true });
// Store only properties that can be changed on this page
@ -204,8 +204,8 @@ define(
}
},
handleFormChange: function (e) {
var item = this.state.item,
field = e.target.name;
const item = this.state.item;
const field = e.target.name;
item[field] = e.target.value;

View File

@ -12,7 +12,7 @@ define(
_
) => {
var fields = [
let fields = [
{
name: 'subject',
label: MailPoet.I18n.t('subjectLine'),
@ -46,7 +46,7 @@ define(
return segment.name + ' (' + parseInt(segment.subscribers, 10).toLocaleString() + ')';
},
transformChangedValue: function (segment_ids) {
var all_segments = this.state.items;
const all_segments = this.state.items;
return _.map(segment_ids, (id) => {
return _.find(all_segments, (segment) => {
return segment.id === id;

View File

@ -14,13 +14,13 @@ define(
Hooks
) => {
var currentTime = window.mailpoet_current_time || '00:00',
defaultDateTime = window.mailpoet_current_date + ' ' + '00:00:00';
timeOfDayItems = window.mailpoet_schedule_time_of_day,
dateDisplayFormat = window.mailpoet_date_display_format,
dateStorageFormat = window.mailpoet_date_storage_format;
const currentTime = window.mailpoet_current_time || '00:00';
const defaultDateTime = window.mailpoet_current_date + ' ' + '00:00:00';
const timeOfDayItems = window.mailpoet_schedule_time_of_day;
const dateDisplayFormat = window.mailpoet_date_display_format;
const dateStorageFormat = window.mailpoet_date_storage_format;
var datepickerTranslations = {
const datepickerTranslations = {
closeText: MailPoet.I18n.t('close'),
currentText: MailPoet.I18n.t('today'),
nextText: MailPoet.I18n.t('next'),
@ -82,18 +82,18 @@ define(
],
};
var DateText = React.createClass({
const DateText = React.createClass({
onChange: function (event) {
// Swap display format to storage format
var displayDate = event.target.value,
storageDate = this.getStorageDate(displayDate);
const displayDate = event.target.value;
const storageDate = this.getStorageDate(displayDate);
event.target.value = storageDate;
this.props.onChange(event);
},
componentDidMount: function () {
var $element = jQuery(this.refs.dateInput),
that = this;
const $element = jQuery(this.refs.dateInput);
const that = this;
if ($element.datepicker) {
// Override jQuery UI datepicker Date parsing and formatting
jQuery.datepicker.parseDate = function (format, value) {
@ -105,7 +105,7 @@ define(
};
jQuery.datepicker.formatDate = function (format, value) {
// Transform Date object to string format
var newValue = MailPoet.Date.format(value, {
const newValue = MailPoet.Date.format(value, {
format: format
});
return newValue;
@ -162,7 +162,7 @@ define(
},
});
var TimeSelect = React.createClass({
const TimeSelect = React.createClass({
render: function () {
const options = Object.keys(timeOfDayItems).map(
(value, index) => {
@ -189,7 +189,7 @@ define(
}
});
var DateTime = React.createClass({
const DateTime = React.createClass({
_DATE_TIME_SEPARATOR: " ",
getInitialState: function () {
return this._buildStateFromProps(this.props);
@ -206,7 +206,7 @@ define(
};
},
handleChange: function (event) {
var newState = {};
const newState = {};
newState[event.target.name] = event.target.value;
this.setState(newState, function () {
@ -246,7 +246,7 @@ define(
}
});
var StandardScheduling = React.createClass({
const StandardScheduling = React.createClass({
_getCurrentValue: function () {
return _.defaults(
this.props.item[this.props.field.name] || {},
@ -257,8 +257,8 @@ define(
);
},
handleValueChange: function (event) {
var oldValue = this._getCurrentValue(),
newValue = {};
const oldValue = this._getCurrentValue();
const newValue = {};
newValue[event.target.name] = event.target.value;
return this.props.onValueChange({
@ -283,7 +283,7 @@ define(
};
},
render: function () {
var schedulingOptions;
let schedulingOptions;
if (this.isScheduled()) {
schedulingOptions = (
@ -317,7 +317,7 @@ define(
},
});
var fields = [
let fields = [
{
name: 'subject',
label: MailPoet.I18n.t('subjectLine'),
@ -345,7 +345,7 @@ define(
return segment.name + ' (' + parseInt(segment.subscribers, 10).toLocaleString() + ')';
},
transformChangedValue: function (segment_ids) {
var all_segments = this.state.items;
const all_segments = this.state.items;
return _.map(segment_ids, (id) => {
return _.find(all_segments, (segment) => {
return segment.id === id;

View File

@ -11,7 +11,7 @@ define(
) => {
var fields = [
let fields = [
{
name: 'subject',
label: MailPoet.I18n.t('subjectLine'),

View File

@ -16,7 +16,7 @@ define(
Breadcrumb
) => {
var ImportTemplate = React.createClass({
const ImportTemplate = React.createClass({
saveTemplate: function (template) {
// Stringify to enable transmission of primitive non-string value types
@ -49,9 +49,9 @@ define(
if (_.size(this.refs.templateFile.files) <= 0) return false;
var file = _.first(this.refs.templateFile.files);
var reader = new FileReader();
var saveTemplate = this.saveTemplate;
const file = _.first(this.refs.templateFile.files);
const reader = new FileReader();
const saveTemplate = this.saveTemplate;
reader.onload = (e) => {
try {
@ -82,7 +82,7 @@ define(
},
});
var NewsletterTemplates = React.createClass({
const NewsletterTemplates = React.createClass({
getInitialState: function () {
return {
loading: false,
@ -131,7 +131,7 @@ define(
});
},
handleSelectTemplate: function (template) {
var body = template.body;
let body = template.body;
// Stringify to enable transmission of primitive non-string value types
if (!_.isUndefined(body)) {
@ -199,8 +199,8 @@ define(
this.getTemplates();
},
render: function () {
var templates = this.state.templates.map((template, index) => {
var deleteLink = (
const templates = this.state.templates.map((template, index) => {
const deleteLink = (
<div className="mailpoet_delete">
<a
href="javascript:;"
@ -209,7 +209,8 @@ define(
{MailPoet.I18n.t('delete')}
</a>
</div>
), thumbnail = '';
);
let thumbnail = '';
if (typeof template.thumbnail === 'string'
&& template.thumbnail.length > 0) {
@ -252,7 +253,7 @@ define(
);
});
var boxClasses = classNames(
const boxClasses = classNames(
'mailpoet_boxes',
'clearfix',
{ 'mailpoet_boxes_loading': this.state.loading }

View File

@ -13,7 +13,7 @@ define(
Router,
Breadcrumb
) => {
var NewsletterTypes = React.createClass({
const NewsletterTypes = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},
@ -43,7 +43,7 @@ define(
});
},
render: function () {
var types = [
let types = [
{
'id': 'standard',
'title': MailPoet.I18n.t('regularNewsletterTypeTitle'),

View File

@ -16,13 +16,13 @@ define(
Breadcrumb
) => {
var field = {
const field = {
name: 'options',
type: 'reactComponent',
component: Scheduling,
};
var NewsletterNotification = React.createClass({
const NewsletterNotification = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},
@ -38,7 +38,7 @@ define(
};
},
handleValueChange: function (event) {
var state = this.state;
const state = this.state;
state[event.target.name] = event.target.value;
this.setState(state);
},

View File

@ -12,7 +12,7 @@ define(
Breadcrumb
) => {
var NewsletterStandard = React.createClass({
const NewsletterStandard = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},

View File

@ -35,7 +35,7 @@ define(
}
};
var Link = Router.Link;
const Link = Router.Link;
const SegmentForm = React.createClass({
render: function () {

View File

@ -5,7 +5,7 @@ import classNames from 'classnames';
import Listing from 'listing/listing.jsx';
var columns = [
const columns = [
{
name: 'name',
label: MailPoet.I18n.t('name'),
@ -196,7 +196,7 @@ const item_actions = [
const SegmentList = React.createClass({
renderItem: function (segment, actions) {
var rowClasses = classNames(
const rowClasses = classNames(
'manage-column',
'column-primary',
'has-row-actions'

View File

@ -13,7 +13,7 @@ define(
Form,
ReactStringReplace
) => {
var fields = [
const fields = [
{
name: 'email',
label: MailPoet.I18n.t('email'),
@ -107,7 +107,7 @@ define(
}
];
var custom_fields = window.mailpoet_custom_fields || [];
const custom_fields = window.mailpoet_custom_fields || [];
custom_fields.map(custom_field => {
const field = {
name: 'cf_' + custom_field.id,
@ -138,7 +138,7 @@ define(
fields.push(field);
});
var messages = {
const messages = {
onUpdate: function () {
MailPoet.Notice.success(MailPoet.I18n.t('subscriberUpdated'));
},
@ -147,7 +147,7 @@ define(
}
};
var beforeFormContent = function (subscriber) {
const beforeFormContent = function (subscriber) {
if (~~(subscriber.wp_user_id) > 0) {
return (
<p className="description">
@ -167,7 +167,7 @@ define(
}
};
var afterFormContent = function () {
const afterFormContent = function () {
return (
<p className="description">
<strong>
@ -177,9 +177,9 @@ define(
);
};
var Link = Router.Link;
const Link = Router.Link;
var SubscriberForm = React.createClass({
const SubscriberForm = React.createClass({
render: function () {
return (
<div>