Skip to content

Commit

Permalink
Add Prettier, ESLint and Husky
Browse files Browse the repository at this point in the history
  • Loading branch information
dubrox committed Jan 14, 2025
1 parent d997145 commit 7badec9
Show file tree
Hide file tree
Showing 17 changed files with 2,289 additions and 646 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout the repository
uses: actions/checkout@v2
- name: Checkout the repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "16"

- name: Install dependencies
run: npm install
- name: Install dependencies
run: npm install

- name: Run tests
run: npm test
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: dubrox/Multiple-Dates-Picker-for-jQuery-UI
- name: Run tests
run: npm test

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: dubrox/Multiple-Dates-Picker-for-jQuery-UI
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.eslintcache
.idea
/node_modules/
/coverage/
/coverage/
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore artifacts:
build
coverage
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
MultiDatesPicker for jQuery UI
==============================
# MultiDatesPicker for jQuery UI

![codecov](https://codecov.io/gh/dubrox/Multiple-Dates-Picker-for-jQuery-UI/branch/main/graph/badge.svg)

This plugin extends the jQuery UI datepicker clendar, allowing to select more than one date,
This plugin extends the jQuery UI datepicker clendar, allowing to select more than one date,
picking them one by one or by ranges relative to the clicked date.

Take a look at [some demos](http://dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI/#demos).

## Install

With any of the following package managers:
With any of the following package managers:

`bower install jquery-ui-multidatespicker`

`npm install jquery-ui-multidatespicker`

`yarn add jquery-ui-multidatespicker`

Download the [zip](https://github.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/archive/latest.zip)
Download the [zip](https://github.com/dubrox/Multiple-Dates-Picker-for-jQuery-UI/archive/latest.zip)
and place wherever you need it:

## Use

For documentation and examples, check
For documentation and examples, check
[the official MDP page](https://dubrox.github.io/Multiple-Dates-Picker-for-jQuery-UI).
34 changes: 18 additions & 16 deletions __tests__/multidatespicker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ describe("MDP Initialization", function () {
document.body.innerHTML = '<input id="datepicker" />';
$input = $("#datepicker");

spyDatepickerUpdate = jest.spyOn($.datepicker, '_updateDatepicker');
spyDatepickerUpdate = jest.spyOn($.datepicker, "_updateDatepicker");

// fix the offsetWidth to make the datepicker visible in jsdom
jest.spyOn($input[0], 'offsetWidth', 'get').mockReturnValue(1);
jest.spyOn($input[0], "offsetWidth", "get").mockReturnValue(1);
});

afterEach(function () {
Expand All @@ -26,27 +26,27 @@ describe("MDP Initialization", function () {

it("should call a beforeShow event with default behavior", function () {
$input.multiDatesPicker();

// triggers the beforeShow event
$input.trigger('focus');
$input.trigger("focus");

expect(spyDatepickerUpdate).toHaveBeenCalledTimes(normalDatepickerUpdates);
});

it("should call a custom beforeShow event that interrupts the default behavior", function () {
const beforeShow = jest.fn(_ => false); // returning false to interrupt the default behavior
const beforeShow = jest.fn((_) => false); // returning false to interrupt the default behavior
$input.multiDatesPicker({ beforeShow });

// triggers the beforeShow event with a custom function
$input.trigger('focus');
$input.trigger("focus");

expect(beforeShow).toHaveBeenCalled();
expect(spyDatepickerUpdate).toHaveBeenCalledTimes(normalDatepickerUpdates - 1);
expect(spyDatepickerUpdate).toHaveBeenCalledTimes(
normalDatepickerUpdates - 1,
);
});
});



describe("setMode", function () {
let $input, date;

Expand Down Expand Up @@ -190,7 +190,7 @@ describe("init", function () {

it("should correctly set disabled dates and update calendar range", function () {
const $input = $('<input type="text" id="test-datepicker">').appendTo(
"body"
"body",
);

// Initialize with options that set minDate and maxDate
Expand Down Expand Up @@ -239,7 +239,9 @@ describe("invalid methods", function () {
it("should error on non-existing method", function () {
expect(function () {
$input.multiDatesPicker("happyNewYear");
}).toThrowError("Method happyNewYear does not exist on jQuery.multiDatesPicker");
}).toThrowError(
"Method happyNewYear does not exist on jQuery.multiDatesPicker",
);
});
});

Expand Down Expand Up @@ -562,7 +564,7 @@ describe("gotDate", function () {
$input.multiDatesPicker(
"addDates",
["10/11/2024", "10/13/2024"],
"disabled"
"disabled",
);
});

Expand Down Expand Up @@ -668,7 +670,7 @@ describe("getDates", function () {
$input.multiDatesPicker(
"addDates",
["10/11/2024", "10/13/2024"],
"disabled"
"disabled",
);
});

Expand All @@ -681,7 +683,7 @@ describe("getDates", function () {
const disabledDates = $input.multiDatesPicker(
"getDates",
"string",
"disabled"
"disabled",
);
expect(disabledDates).toEqual(["10/11/2024", "10/13/2024"]);
});
Expand All @@ -699,7 +701,7 @@ describe("getDates", function () {
const disabledDates = $input.multiDatesPicker(
"getDates",
"object",
"disabled"
"disabled",
);
expect(disabledDates).toEqual([
new Date("10/11/2024"),
Expand All @@ -720,7 +722,7 @@ describe("getDates", function () {
const disabledDates = $input.multiDatesPicker(
"getDates",
"number",
"disabled"
"disabled",
);
expect(disabledDates).toEqual([
Date.parse("10/11/2024"),
Expand Down
26 changes: 5 additions & 21 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,12 @@
"name": "jquery-ui-multidatespicker",
"description": "Extension to the jQuery UI Calendar allowing multiple selections",
"license": "(MIT OR GPLv2)",
"authors": [
"Luca Lauretta <[email protected]>"
],
"main": [
"jquery-ui.multidatespicker.js",
"jquery-ui.multidatespicker.css"
],
"authors": ["Luca Lauretta <[email protected]>"],
"main": ["jquery-ui.multidatespicker.js", "jquery-ui.multidatespicker.css"],
"dependencies": {
"jquery": "1.9.1 - 3.7.x",
"jquery-ui": "1.7.0 - 1.14.x"
},
"keywords": [
"jquery",
"jquery-ui",
"calendar",
"dates"
],
"ignore": [
"**/.*",
"*.ico",
"*.png",
"package.json",
"index.html"
]
}
"keywords": ["jquery", "jquery-ui", "calendar", "dates"],
"ignore": ["**/.*", "*.ico", "*.png", "package.json", "index.html"]
}
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import globals from "globals";
import pluginJs from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier";

/** @type {import('eslint').Linter.Config[]} */
export default [
{ languageOptions: { globals: globals.browser } },
eslintConfigPrettier,
pluginJs.configs.recommended,
{
rules: {
"no-fallthrough": "off",
"no-undef": "warn",
"no-unused-vars": "warn",
},
},
];
Loading

0 comments on commit 7badec9

Please sign in to comment.