Skip to content

Linting #583

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
626 changes: 319 additions & 307 deletions .eslintrc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ Here are a couple of guidelines that will help you contribute. Before we get sta
```shell
$ git commit -m "A brief summary of the commit"
>
> A paragraph describing what changed and its impact."
> A paragraph describing what changed and its impact.
```
* If your PR fixes a separate issue number, include it in the commit message.

87 changes: 45 additions & 42 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
'use strict';

module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
meta: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %> */'
eslint : {
options : {
quiet : true
},
target : ['src/**/*.js']
},

githooks: {
options: {
hashbang: '#!/bin/sh',
template: 'install/template/shell.hb',
startMarker: '# GRUNT-GITHOOKS START',
endMarker: '# GRUNT-GITHOOKS END'
githooks : {
all : {
'pre-commit' : 'pre-commit'
},
all: {
'pre-commit': 'pre-commit'
options : {
endMarker : '# GRUNT-GITHOOKS END',
hashbang : '#!/bin/sh',
startMarker : '# GRUNT-GITHOOKS START',
template : 'install/template/shell.hb'
}
},

eslint: {
options: {
quiet: true
},
target: ['src/**/*.js']
meta : {
banner : '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd HH:MM:ss") %> */'
},

mocha: {
all: {
src: ['test/*.html']
mocha : {
all : {
src : ['test/*.html']
},
options: {
run: true,
growlOnSuccess: false
options : {
growlOnSuccess : false,
run : true
}
},

pkg : grunt.file.readJSON('package.json'),

// Minifies JS files
uglify: {
options: {
output: {
comments: /^!|@preserve|@license|@cc_on/i
},
sourceMap: true,
footer: '\n'
},
dist: {
files: [{
expand: true,
cwd: 'src',
src: ['*.js','!*.min.js'],
dest: 'dist',
ext: '.min.js',
extDot: 'last'
uglify : {
dist : {
files : [{
cwd : 'src',
dest : 'dist',
expand : true,
ext : '.min.js',
extDot : 'last',
src : ['*.js', '!*.min.js']
}]
},
options : {
footer : '\n',
output : {
comments : /^!|@preserve|@license|@cc_on/i
},
sourceMap : true
}
}
});
@@ -63,8 +66,8 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-githooks');

// Default task.
grunt.registerTask('lint', [ 'eslint' ]);
grunt.registerTask('test', [ 'lint', 'mocha' ]);
grunt.registerTask('pre-commit', [ 'test' ]);
grunt.registerTask('default', [ 'test', 'uglify' ]);
grunt.registerTask('lint', ['eslint']);
grunt.registerTask('test', ['lint', 'mocha']);
grunt.registerTask('pre-commit', ['test']);
grunt.registerTask('default', ['test', 'uglify']);
};
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@ The jqXHR object is stored in element <em>data</em>-cache with the <code>jqxhr</
call. It can be accessed like this:

````javascript
var form = $('#myForm').ajaxSubmit({ /* options */ });
var xhr = form.data('jqxhr');
const form = $('#myForm').ajaxSubmit({ /* options */ });
const xhr = form.data('jqxhr');

xhr.done(function() {
...
@@ -89,7 +89,7 @@ $('form').on('submit', function(e) {
Callback function invoked before form serialization. Provides an opportunity to manipulate the form before its values are retrieved. Returning `false` from the callback will prevent the form from being submitted. The callback is invoked with two arguments: the jQuery wrapped form object and the options object.

````javascript
beforeSerialize: function($form, options) {
beforeSerialize ($form, options) {
// return false to cancel submit
}
````
@@ -98,7 +98,7 @@ beforeSerialize: function($form, options) {
Callback function invoked before form submission. Returning `false` from the callback will prevent the form from being submitted. The callback is invoked with three arguments: the form data in array format, the jQuery wrapped form object, and the options object.

````javascript
beforeSubmit: function(arr, $form, options) {
beforeSubmit (arr, $form, options) {
// form data array is an array of objects with name and value properties
// [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
// return false to cancel submit
@@ -109,7 +109,7 @@ beforeSubmit: function(arr, $form, options) {
Callback function invoked before form events unbind and bind again. Provides an opportunity to manipulate the form before events will be remounted. The callback is invoked with two arguments: the jQuery wrapped form object and the options object.

````javascript
beforeFormUnbind: function($form, options) {
beforeFormUnbind ($form, options) {
// your callback code
}
````
@@ -118,7 +118,7 @@ beforeFormUnbind: function($form, options) {
Callback function invoked before processing fields. This provides a way to filter elements.

````javascript
filtering: function(el, index) {
filtering (el, index) {
if ( !$(el).hasClass('ignore') ) {
return el;
}
@@ -216,14 +216,14 @@ URL to which the form data will be submitted.
Serializes the form into a query string. This method will return a string in the format: `name1=value1&name2=value2`

````javascript
var queryString = $('#myFormId').formSerialize();
const queryString = $('#myFormId').formSerialize();
````

### fieldSerialize
Serializes field elements into a query string. This is handy when you need to serialize only part of a form. This method will return a string in the format: `name1=value1&name2=value2`

````javascript
var queryString = $('#myFormId .specialFields').fieldSerialize();
const queryString = $('#myFormId .specialFields').fieldSerialize();
````

### fieldValue
14 changes: 7 additions & 7 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link href='https://fonts.googleapis.com/css?family=Chivo:900' rel='stylesheet' type='text/css'>
<link href="https://fonts.googleapis.com/css?family=Chivo:900" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}">
<link rel="stylesheet" type="text/css" href="{{ '/assets/css/print.css' | relative_url }}" media="print">
<!--[if lt IE 9]>
@@ -33,12 +33,12 @@ <h2>{{ site.description | default: site.github.project_tagline }}</h2>

<nav>
<ul>
<li class="{% if page.url == "/" %}active{% endif %}"><a href="{{ site.baseurl }}/">Getting Started</a></li>
<li class="{% if page.url == "/api/" %}active{% endif %}"><a href="{{ site.baseurl }}/api/">API</a></li>
<li class="{% if page.url == "/options/" %}active{% endif %}"><a href="{{ site.baseurl }}/options/">Options</a></li>
<li class="{% if page.url == "/examples/" %}active{% endif %}"><a href="{{ site.baseurl }}/examples/">Examples</a></li>
<li class="{% if page.url == "/form-fields/" %}active{% endif %}"><a href="{{ site.baseurl }}/form-fields/">Form Fields</a></li>
<li class="{% if page.url == "/faq/" %}active{% endif %}"><a href="{{ site.baseurl }}/faq/">FAQ</a></li>
<li class="{% if page.url == '/' %}active{% endif %}"><a href="{{ site.baseurl }}/">Getting Started</a></li>
<li class="{% if page.url == '/api/' %}active{% endif %}"><a href="{{ site.baseurl }}/api/">API</a></li>
<li class="{% if page.url == '/options/' %}active{% endif %}"><a href="{{ site.baseurl }}/options/">Options</a></li>
<li class="{% if page.url == '/examples/' %}active{% endif %}"><a href="{{ site.baseurl }}/examples/">Examples</a></li>
<li class="{% if page.url == '/form-fields/' %}active{% endif %}"><a href="{{ site.baseurl }}/form-fields/">Form Fields</a></li>
<li class="{% if page.url == '/faq/' %}active{% endif %}"><a href="{{ site.baseurl }}/faq/">FAQ</a></li>
<li><a href="{{ site.github.repository_url | replace_first: 'http:', 'https:' }}#download">Download</a></li>
</ul>
</nav>
1,698 changes: 375 additions & 1,323 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -26,11 +26,19 @@
"type": "git",
"url": "https://github.com/jquery-form/form.git"
},
"scripts": {
"lint": "eslint --report-unused-disable-directives .",
"test": "grunt test"
},
"engines": {
"node": ">=8.0.0"
},
"dependencies": {
"jquery": ">=1.7.2"
"jquery": ">=1.9.1"
},
"devDependencies": {
"chai": "^4.2.0",
"eslint": "^7.4.0",
"grunt": "^1.1.0",
"grunt-cli": "^1.3.2",
"grunt-contrib-uglify": "^4.0.1",
785 changes: 415 additions & 370 deletions src/jquery.form.js

Large diffs are not rendered by default.

48 changes: 25 additions & 23 deletions test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
'use strict';

module.exports = {
"env": {
"browser": true,
"jquery": true,
"node": true,
"mocha": true
env : {
browser : true,
jquery : true,
mocha : true,
node : true
},
"parserOptions": {
"ecmaVersion": 5,
"sourceType": "script"
parserOptions : {
ecmaVersion : 2015,
sourceType : 'script'
},
"rules": {
"comma-spacing": "warn",
"eqeqeq": "warn",
"newline-after-var": "off",
"newline-before-return": "off",
"no-multi-spaces": "warn",
"object-curly-spacing": [
"warn",
"never",
rules : {
'comma-spacing' : 'warn',
'eqeqeq' : 'warn',
'newline-after-var' : 'off',
'newline-before-return' : 'off',
'no-multi-spaces' : 'warn',
'object-curly-spacing' : [
'warn',
'never',
{
"arraysInObjects": true,
"objectsInObjects": true
arraysInObjects : true,
objectsInObjects : true
}
],
"strict": [
"warn",
"global"
'strict' : [
'warn',
'global'
],
"yoda": "warn"
'yoda' : 'warn'
}
};
55 changes: 28 additions & 27 deletions test/ajax/doc-with-scripts.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<div>

Lorem ipsum dolor sit amet

<script type="text/javascript">
// set global var
var unitTestVariable1 = true;
</script>

Lorem ipsum dolor sit amet

<script type="text/javascript">
// set another global var
var unitTestVariable2 = true;
</script>

<script type="text/javascript">
// set global var
if (typeof scriptCount == 'undefined')
var scriptCount = 1;
else
scriptCount++;
</script>

Lorem ipsum dolor sit amet

</div>
<!DOCTYPE html>
<div>

Lorem ipsum dolor sit amet

<script type="text/javascript">
// set global var
var unitTestVariable1 = true;
</script>

Lorem ipsum dolor sit amet

<script type="text/javascript">
// set another global var
var unitTestVariable2 = true;
</script>

<script type="text/javascript">
// set global var
if (typeof scriptCount == 'undefined')
var scriptCount = 1;
else
scriptCount++;
</script>

Lorem ipsum dolor sit amet

</div>
25 changes: 13 additions & 12 deletions test/ajax/text.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Lorem ipsum dolor sit amet
consectetuer adipiscing elit
Sed lorem leo
lorem leo consectetuer adipiscing elit
Sed lorem leo
rhoncus sit amet
elementum at
bibendum at, eros
Cras at mi et tortor egestas vestibulum
sed Cras at mi vestibulum
Phasellus sed felis sit amet
orci dapibus semper.
<!DOCTYPE html>
Lorem ipsum dolor sit amet
consectetuer adipiscing elit
Sed lorem leo
lorem leo consectetuer adipiscing elit
Sed lorem leo
rhoncus sit amet
elementum at
bibendum at, eros
Cras at mi et tortor egestas vestibulum
sed Cras at mi vestibulum
Phasellus sed felis sit amet
orci dapibus semper.
4 changes: 2 additions & 2 deletions test/test.html
Original file line number Diff line number Diff line change
@@ -154,8 +154,8 @@
<input type="checkbox" name="Check" value="1">
<input type="checkbox" name="Check" value="2" checked="checked">
<select name="Select">
<option value="opt1">
<option value="opt2" selected="selected">
<option value="opt1" />
<option value="opt2" selected="selected" />
</select>
<input type="submit" value="button">
</div>
616 changes: 328 additions & 288 deletions test/test.js

Large diffs are not rendered by default.