Skip to content

Commit 4658552

Browse files
committed
Enforce linting and fix lint errors
1 parent af4e50a commit 4658552

File tree

9 files changed

+396
-64
lines changed

9 files changed

+396
-64
lines changed

.eslintrc.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
module.exports = {
22
root: true,
3-
extends: "eslint:recommended",
3+
extends: 'eslint:recommended',
44
globals: {
55
wp: true,
6+
SetFieldProperty: true,
7+
gform: true,
8+
GetInputType: true,
9+
GetSelectedField: true,
610
},
711
env: {
812
node: true,
@@ -18,27 +22,27 @@ module.exports = {
1822
objectLiteralDuplicateProperties: false,
1923
},
2024
ecmaVersion: 2017,
21-
sourceType: "module",
25+
sourceType: 'module',
2226
},
23-
plugins: ["import"],
27+
plugins: ['import'],
2428
settings: {
25-
"import/core-modules": [],
26-
"import/ignore": [
27-
"node_modules",
28-
"\\.(coffee|scss|css|less|hbs|svg|json)$",
29+
'import/core-modules': [],
30+
'import/ignore': [
31+
'node_modules',
32+
'\\.(coffee|scss|css|less|hbs|svg|json)$',
2933
],
3034
},
3135
rules: {
32-
"no-console": 0,
33-
quotes: ["error", "single"],
34-
"comma-dangle": [
35-
"error",
36+
'no-console': 0,
37+
quotes: ['error', 'single'],
38+
'comma-dangle': [
39+
'error',
3640
{
37-
arrays: "always-multiline",
38-
objects: "always-multiline",
39-
imports: "always-multiline",
40-
exports: "always-multiline",
41-
functions: "ignore",
41+
arrays: 'always-multiline',
42+
objects: 'always-multiline',
43+
imports: 'always-multiline',
44+
exports: 'always-multiline',
45+
functions: 'ignore',
4246
},
4347
],
4448
},

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 1.0.1 / 2018-12-1
4+
5+
- Add pre-commit lint
6+
- Fix JS linter errors
7+
38
## 1.0.0 / 2018-12-1
49

510
- Initial release

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- [Usage](#usage)
44
- [Installation](#installation)
5+
- [Contributing](#contributing)
56
- [Screenshots](#screenshots)
67

78
This plugin allows you to add custom data attributes to Gravity Forms fields.
@@ -30,6 +31,18 @@ There are three options for installing this plugin:
3031
2. With [GitHub Updater](https://github.com/afragen/github-updater)
3132
3. By downloading the latest release ZIP from this repository and installing it like any normal WordPress plugin
3233

34+
## Contributing
35+
36+
To work on this project (for yourself or to contribute a PR):
37+
38+
1. Clone this repo
39+
2. Run `composer install`
40+
3. Run `yarn` or `npm install`
41+
42+
And you should be good to go.
43+
44+
Pre-commit linting is enforced (see `.eslintrc.js` and `.stylelintrc.js` for scripts and styles; PHP users PSR-2).
45+
3346
## Screenshots
3447

3548
_Settings for a field without choices_

app/admin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Add "Enable Data Attributes" and "Data Attribute Names" settings
2020
add_action('gform_field_standard_settings', function ($position, $form_id) {
2121
if ($position === 1350) :
22-
?>
22+
?>
2323
<li class="enable_data_attrs_setting field_setting">
2424
<input type="checkbox" id="field_enable_data_attrs_value" onclick="ToggleDataAttrs();" />
2525
<label for="field_enable_data_attrs_value" class="inline">
@@ -38,7 +38,7 @@
3838
<div id="gform_data_attr_inputs"></div>
3939
</div>
4040
</li>
41-
<?php
41+
<?php
4242
endif;
4343
}, 10, 2);
4444

@@ -56,5 +56,5 @@
5656
fieldSettings[i] += ", .enable_data_attrs_setting, .data_attrs_setting";
5757
}
5858
</script>
59-
<?php
59+
<?php
6060
});

assets/admin.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77

88
// Show/hide the "Data Attribute Names" setting and the settings for individual data attributes
99
function ToggleDataAttrs(isInit) {
10-
var speed = isInit ? "" : "slow";
10+
var speed = isInit ? '' : 'slow';
1111

12-
if (jQuery("#field_enable_data_attrs_value").is(":checked")) {
13-
jQuery("#gform_data_attrs, .field-choice-data-attr-wrapper").show(speed);
12+
if (jQuery('#field_enable_data_attrs_value').is(':checked')) {
13+
jQuery('#gform_data_attrs, .field-choice-data-attr-wrapper').show(speed);
1414

15-
SetFieldProperty("enableDataAttrsField", true);
15+
SetFieldProperty('enableDataAttrsField', true);
1616
} else {
17-
jQuery("#gform_data_attrs, .field-choice-data-attr-wrapper").hide(speed);
18-
SetFieldProperty("enableDataAttrsField", false);
19-
SetFieldProperty("dataAttrsField", "");
17+
jQuery('#gform_data_attrs, .field-choice-data-attr-wrapper').hide(speed);
18+
SetFieldProperty('enableDataAttrsField', false);
19+
SetFieldProperty('dataAttrsField', '');
2020
}
2121
}
2222

@@ -25,106 +25,106 @@ function ToggleDataAttrs(isInit) {
2525
* 1. Initialize "Enable Data Attributes" and "Data Attribute Names" settings
2626
* 2. If the field doesn't have choices, add the field for each data attribute
2727
*/
28-
jQuery(document).on("gform_load_field_settings", function(event, field, form) {
29-
jQuery("#field_enable_data_attrs_value").attr(
30-
"checked",
28+
jQuery(document).on('gform_load_field_settings', function(event, field) {
29+
jQuery('#field_enable_data_attrs_value').attr(
30+
'checked',
3131
field.enableDataAttrsField == true
3232
);
3333

34-
var dataAttrsInputContainer = jQuery("#gform_data_attr_inputs");
35-
dataAttrsInputContainer.html("");
34+
var dataAttrsInputContainer = jQuery('#gform_data_attr_inputs');
35+
dataAttrsInputContainer.html('');
3636

37-
jQuery("#field_data_attrs").val(field.dataAttrsField);
37+
jQuery('#field_data_attrs').val(field.dataAttrsField);
3838

3939
var dataAttrs = field.dataAttrsField;
4040

4141
if (field.choices || !dataAttrs)
4242
return ToggleDataAttrs(!field.enableDataAttrsField);
4343

44-
dataAttrs = dataAttrs.split("\n").map(function(name) {
44+
dataAttrs = dataAttrs.split('\n').map(function(name) {
4545
return {
4646
name: name,
47-
value: field[name] || "",
47+
value: field[name] || '',
4848
};
4949
});
5050

5151
var inputs = dataAttrs
5252
.map(function(dataAttr) {
5353
return (
54-
"<br><label class='section_label'>" +
54+
'<br><label class=\'section_label\'>' +
5555
dataAttr.name +
56-
"</label><input type='text' id='" +
56+
'</label><input type=\'text\' id=\'' +
5757
dataAttr.name +
58-
"' value='" +
58+
'\' value=\'' +
5959
dataAttr.value +
60-
"' class='field-" +
60+
'\' class=\'field-' +
6161
dataAttr.name +
62-
" field-data-attr' data-attr-name='" +
62+
' field-data-attr\' data-attr-name=\'' +
6363
dataAttr.name +
64-
"' /><br>"
64+
'\' /><br>'
6565
);
6666
})
67-
.join("");
67+
.join('');
6868

6969
dataAttrsInputContainer.html(inputs);
7070

7171
ToggleDataAttrs(!field.enableDataAttrsField);
7272
});
7373

7474
// Add the field for each data attribute when fields choices are rendered
75-
gform.addFilter("gform_append_field_choice_option", function(str, field, i) {
75+
gform.addFilter('gform_append_field_choice_option', function(str, field, i) {
7676
var inputType = GetInputType(field);
7777

7878
var dataAttrs = field.dataAttrsField;
7979

80-
if (!dataAttrs) return "";
80+
if (!dataAttrs) return '';
8181

82-
dataAttrs = dataAttrs.split("\n").map(function(name) {
82+
dataAttrs = dataAttrs.split('\n').map(function(name) {
8383
return {
8484
name: name,
85-
value: field.choices[i][name] || "",
85+
value: field.choices[i][name] || '',
8686
};
8787
});
8888

8989
var inputs = dataAttrs
9090
.map(function(dataAttr) {
91-
var id = inputType + "_choice_" + dataAttr.name + "_" + i;
91+
var id = inputType + '_choice_' + dataAttr.name + '_' + i;
9292
return (
93-
"<label>" +
93+
'<label>' +
9494
dataAttr.name +
95-
" <input type='text' id='" +
95+
' <input type=\'text\' id=\'' +
9696
id +
97-
"' value='" +
97+
'\' value=\'' +
9898
dataAttr.value +
99-
"' class='field-choice-input field-choice-" +
99+
'\' class=\'field-choice-input field-choice-' +
100100
dataAttr.name +
101-
" field-choice-data-attr' data-attr-name='" +
101+
' field-choice-data-attr\' data-attr-name=\'' +
102102
dataAttr.name +
103-
"' /></label>"
103+
'\' /></label>'
104104
);
105105
})
106-
.join("");
106+
.join('');
107107

108-
return "<div class='field-choice-data-attr-wrapper'>" + inputs + "</div>";
108+
return '<div class=\'field-choice-data-attr-wrapper\'>' + inputs + '</div>';
109109
});
110110

111111
// save data attribute values (general / non-choices)
112-
jQuery(document).on("input propertychange", ".field-data-attr", function() {
112+
jQuery(document).on('input propertychange', '.field-data-attr', function() {
113113
var $this = jQuery(this);
114114

115115
var field = GetSelectedField();
116-
field[$this.data("attrName")] = $this.val();
116+
field[$this.data('attrName')] = $this.val();
117117
});
118118

119119
// save data attribute values (choices)
120120
jQuery(document).on(
121-
"input propertychange",
122-
".field-choice-data-attr",
121+
'input propertychange',
122+
'.field-choice-data-attr',
123123
function() {
124124
var $this = jQuery(this);
125-
var i = $this.closest("li.field-choice-row").data("index");
125+
var i = $this.closest('li.field-choice-row').data('index');
126126

127127
var field = GetSelectedField();
128-
field.choices[i][$this.data("attrName")] = $this.val();
128+
field.choices[i][$this.data('attrName')] = $this.val();
129129
}
130130
);

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,13 @@
2121
"require": {
2222
"php": ">=7.1.0",
2323
"composer/installers": "^1.6"
24+
},
25+
"require-dev": {
26+
"squizlabs/php_codesniffer": "^3.3"
27+
},
28+
"scripts": {
29+
"test": [
30+
"phpcs -n --standard=PSR2 *.php app/"
31+
]
2432
}
2533
}

0 commit comments

Comments
 (0)