diff --git a/.eslintrc.json b/.eslintrc.json index e3cd587..bdaf046 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -14,10 +14,6 @@ "plugins": [ "ava" ], - "ignorePatterns": [ - "gulpfile.js", - "webpack.config.js" - ], "rules": { "indent": [ "error", diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 96d6b12..13bd48a 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -9,14 +9,14 @@ # the `language` matrix defined below to confirm you have the correct set of # supported CodeQL languages. # -name: "CodeQL" +name: 'CodeQL' on: push: - branches: [ main ] + branches: [main] pull_request: # The branches below must be a subset of the branches above - branches: [ main ] + branches: [main] schedule: - cron: '39 19 * * 4' @@ -32,40 +32,40 @@ jobs: strategy: fail-fast: false matrix: - language: [ 'javascript' ] + language: ['javascript'] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] # Learn more: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - #- name: Autobuild - # uses: github/codeql-action/autobuild@v1 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + #- name: Autobuild + # uses: github/codeql-action/autobuild@v1 - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - - run: | - npm install - npm run build-prod + - run: | + npm install + npm run build-prod - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1043ead..f6dda47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,13 +5,12 @@ name: Node.js CI on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: build: - runs-on: ubuntu-latest strategy: @@ -20,10 +19,10 @@ jobs: # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - - run: npm ci --omit=dev --ignore-scripts - - run: npm run build-prod + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm ci --omit=dev --ignore-scripts + - run: npm run build-prod diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..231745a --- /dev/null +++ b/.prettierignore @@ -0,0 +1,8 @@ +.idea +build +coverage +node_modules +vendor +.eslintrc.json +composer.lock +LICENSE.md diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..b2095be --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "semi": false, + "singleQuote": true +} diff --git a/README.md b/README.md index 8189c11..bc978f6 100644 --- a/README.md +++ b/README.md @@ -7,15 +7,18 @@ More details can be found in the [WordPress Plugin Directory](https://wordpress. ## Development ### Setup + 1. Make sure `npm` and `composer` are installed. 2. Run: `npm install` 3. Run: `composer install` ### Development build + 1. Build: `npm run build-dev` 2. Make sure to keep `changelog.txt` up-to-date. ### Release procedure + 1. Make sure `changelog.txt` is up-to-date. Use a new version number and copy over the new section into `readme.txt`. 2. Update `package.json` with the same version number. 3. Update the `package-lock.json`: `npm i --package-lock-only` @@ -31,9 +34,11 @@ More details can be found in the [WordPress Plugin Directory](https://wordpress. 13. Push the new tag to the repository: `git push --tags` ### Other commands + - Run ESLint: `npm run eslint` - Run JavaScript code coverage with tests: `npm run coverage` - Run tests: `npm test` - Delete build folder: `npm run clean` - Update PHP dependencies: `composer update` - Check for direct PHP dependency updates: `composer outdated --direct` +- Format code with prettier: `npm run format` diff --git a/composer.json b/composer.json index 4014bcb..57e8546 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "require": { - "bartlett/php-compatinfo": "^5.4" - } + "require": { + "bartlett/php-compatinfo": "^5.4" + } } diff --git a/gulpfile.js b/gulpfile.js index f38bcdb..54591a0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,30 +1,49 @@ -const { dest, src } = require('gulp'); +/* eslint-disable no-undef */ +const { dest, src } = require('gulp') -const replace = require('gulp-replace'); +const replace = require('gulp-replace') -const PACKAGE = require('./package.json'); +const PACKAGE = require('./package.json') -const FOLDER_BUILD = './build'; +const FOLDER_BUILD = './build' function injectMetadata() { - return src([ - FOLDER_BUILD + '/' + PACKAGE.name + '/front/events-loader.js', - FOLDER_BUILD + '/' + PACKAGE.name + '/' + PACKAGE.name + '.php', - FOLDER_BUILD + '/' + PACKAGE.name + '/includes/constants.php', - FOLDER_BUILD + '/' + PACKAGE.name + '/readme.txt' - ], { base: './' }) + return src( + [ + FOLDER_BUILD + '/' + PACKAGE.name + '/front/events-loader.js', + FOLDER_BUILD + '/' + PACKAGE.name + '/' + PACKAGE.name + '.php', + FOLDER_BUILD + '/' + PACKAGE.name + '/includes/constants.php', + FOLDER_BUILD + '/' + PACKAGE.name + '/readme.txt', + ], + { base: './' } + ) .pipe(replace('', PACKAGE.author.name)) .pipe(replace('', PACKAGE.author.url)) .pipe(replace('', PACKAGE.description)) .pipe(replace('', PACKAGE.funding.url)) .pipe(replace('', PACKAGE.license)) - .pipe(replace('', PACKAGE.additionalDetails.wordpressMinimumVersion)) + .pipe( + replace( + '', + PACKAGE.additionalDetails.wordpressMinimumVersion + ) + ) .pipe(replace('', PACKAGE.name)) .pipe(replace('', PACKAGE.additionalDetails.niceName)) - .pipe(replace('', PACKAGE.additionalDetails.phpMinimumVersion)) - .pipe(replace('', PACKAGE.additionalDetails.wordpressTestedUpToVersion)) + .pipe( + replace( + '', + PACKAGE.additionalDetails.phpMinimumVersion + ) + ) + .pipe( + replace( + '', + PACKAGE.additionalDetails.wordpressTestedUpToVersion + ) + ) .pipe(replace('', PACKAGE.version)) - .pipe(dest('.')); + .pipe(dest('.')) } -exports.inject = injectMetadata; +exports.inject = injectMetadata diff --git a/package-lock.json b/package-lock.json index 05e50a0..08f26ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "gulp-replace": "^1.1.3", "husky": "^7.0.4", "jsdom": "^19.0.0", + "prettier": "2.5.1", "rimraf": "^3.0.2", "webpack": "^5.65.0", "webpack-cli": "^4.9.1" @@ -7213,6 +7214,18 @@ "node": ">=4" } }, + "node_modules/prettier": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", + "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", + "dev": true, + "bin": { + "prettier": "bin-prettier.js" + }, + "engines": { + "node": ">=10.13.0" + } + }, "node_modules/pretty-hrtime": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", @@ -15403,6 +15416,12 @@ "integrity": "sha1-6SQ0v6XqjBn0HN/UAddBo8gZ2Jc=", "dev": true }, + "prettier": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", + "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", + "dev": true + }, "pretty-hrtime": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", diff --git a/package.json b/package.json index 7ab142d..2ddc6b9 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "clean": "rimraf -- build", "coverage": "c8 --all --reporter=html --reporter=text --include=source/**/*.js ava", "eslint": "npx eslint source/**/*.js", + "format": "npx prettier --write .", "prepare": "husky install", "test": "ava" }, @@ -38,6 +39,7 @@ "gulp-replace": "^1.1.3", "husky": "^7.0.4", "jsdom": "^19.0.0", + "prettier": "2.5.1", "rimraf": "^3.0.2", "webpack": "^5.65.0", "webpack-cli": "^4.9.1" diff --git a/source/connector-mobilizon/changelog.txt b/source/connector-mobilizon/changelog.txt index d1d1ff2..2bc9f8c 100644 --- a/source/connector-mobilizon/changelog.txt +++ b/source/connector-mobilizon/changelog.txt @@ -1,6 +1,7 @@ ### [Unreleased] #### Added - Add specific error message for the case the group is not found +- Add code formatter prettier #### Changed - Set minimum PHP version to oldest officially supported 7.4 - Update dependencies diff --git a/source/connector-mobilizon/front/date-time-wrapper-test.js b/source/connector-mobilizon/front/date-time-wrapper-test.js index c7e6141..7d0f042 100644 --- a/source/connector-mobilizon/front/date-time-wrapper-test.js +++ b/source/connector-mobilizon/front/date-time-wrapper-test.js @@ -1,67 +1,76 @@ import test from 'ava' import DateTimeWrapper from './date-time-wrapper' -test('#getShortDate usual date', t => { +test('#getShortDate usual date', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) t.is(d.getShortDate(), '24/12/2020') }) -test('#getShortDate usual date with timezone string', t => { - const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: 'Europe/Rome' }) +test('#getShortDate usual date with timezone string', (t) => { + const d = new DateTimeWrapper({ + text: '2020-12-24T16:45:00Z', + timeZone: 'Europe/Rome', + }) t.is(d.getShortDate(), '24/12/2020') }) -test('#getShortDate usual date with fixed offset', t => { - const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: 'UTC+02:00' }) +test('#getShortDate usual date with fixed offset', (t) => { + const d = new DateTimeWrapper({ + text: '2020-12-24T16:45:00Z', + timeZone: 'UTC+02:00', + }) t.is(d.getShortDate(), '24/12/2020') }) -test('#getShortDate usual date with fixed offset without UTC prefix', t => { - const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: '+02:00' }) +test('#getShortDate usual date with fixed offset without UTC prefix', (t) => { + const d = new DateTimeWrapper({ + text: '2020-12-24T16:45:00Z', + timeZone: '+02:00', + }) t.is(d.getShortDate(), '24/12/2020') }) -test('#getShortDate usual date with empty time zone', t => { +test('#getShortDate usual date with empty time zone', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z', timeZone: '' }) t.is(d.getShortDate(), '24/12/2020') }) -test('#get24Time usual time', t => { +test('#get24Time usual time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) t.is(d.get24Time(), '16:45') }) -test('#equalsDate same date, different time', t => { +test('#equalsDate same date, different time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const e = new DateTimeWrapper({ text: '2020-12-24T17:46:01Z' }) t.true(d.equalsDate(e)) }) -test('#equalsDate different date, different time', t => { +test('#equalsDate different date, different time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const e = new DateTimeWrapper({ text: '2021-11-25T17:46:01Z' }) t.false(d.equalsDate(e)) }) -test('#equalsDate different day, different time', t => { +test('#equalsDate different day, different time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const e = new DateTimeWrapper({ text: '2020-12-25T17:46:01Z' }) t.false(d.equalsDate(e)) }) -test('#equalsDate different month, different time', t => { +test('#equalsDate different month, different time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const e = new DateTimeWrapper({ text: '2020-11-24T17:46:01Z' }) t.false(d.equalsDate(e)) }) -test('#equalsDate different year, different time', t => { +test('#equalsDate different year, different time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) const e = new DateTimeWrapper({ text: '2021-12-24T17:46:01Z' }) t.false(d.equalsDate(e)) }) -test('#getCurrentDatetimeAsString correct format', t => { +test('#getCurrentDatetimeAsString correct format', (t) => { const d = DateTimeWrapper.getCurrentDatetimeAsString() t.is(d[4], '-') t.is(d[7], '-') @@ -69,10 +78,10 @@ test('#getCurrentDatetimeAsString correct format', t => { t.is(d[13], ':') t.is(d[16], ':') t.is(d[19], '.') - t.is(d[d.length-3], ':') + t.is(d[d.length - 3], ':') }) -test('#getShortOffsetName usual time', t => { +test('#getShortOffsetName usual time', (t) => { const d = new DateTimeWrapper({ text: '2020-12-24T16:45:00Z' }) t.is(d.getShortOffsetName(), 'UTC') }) diff --git a/source/connector-mobilizon/front/date-time-wrapper.js b/source/connector-mobilizon/front/date-time-wrapper.js index 60a5185..c31638e 100644 --- a/source/connector-mobilizon/front/date-time-wrapper.js +++ b/source/connector-mobilizon/front/date-time-wrapper.js @@ -1,12 +1,14 @@ import { DateTime } from 'luxon' export default class DateTimeWrapper { - constructor({ locale = 'en-GB', text, timeZone = 'utc' } = {}) { if (!timeZone) { timeZone = 'utc' } - if (timeZone.includes(':') && timeZone.substring(0, 3).toUpperCase() !== 'UTC') { + if ( + timeZone.includes(':') && + timeZone.substring(0, 3).toUpperCase() !== 'UTC' + ) { timeZone = 'UTC' + timeZone } this.dateTime = DateTime.fromISO(text, { locale, zone: timeZone }) @@ -25,11 +27,13 @@ export default class DateTimeWrapper { } equalsDate(other) { - return this.dateTime && + return ( + this.dateTime && other.dateTime && this.dateTime.day === other.dateTime.day && this.dateTime.month === other.dateTime.month && this.dateTime.year === other.dateTime.year + ) } static getCurrentDatetimeAsString() { diff --git a/source/connector-mobilizon/front/events-displayer-test.js b/source/connector-mobilizon/front/events-displayer-test.js index e6a4662..2798b4a 100644 --- a/source/connector-mobilizon/front/events-displayer-test.js +++ b/source/connector-mobilizon/front/events-displayer-test.js @@ -9,7 +9,7 @@ test.before(() => { document = new JSDOM().window.document }) -test.beforeEach(t => { +test.beforeEach((t) => { t.context.list = document.createElement('ul') t.context.list.setAttribute('data-locale', 'en-GB') t.context.list.setAttribute('data-maximum', '2') @@ -22,7 +22,7 @@ test.beforeEach(t => { t.context.list.appendChild(listElement2) }) -test('#displayEvents one event', t => { +test('#displayEvents one event', (t) => { const list = t.context.list const data = { events: { @@ -34,11 +34,11 @@ test('#displayEvents one event', t => { endsOn: '2021-04-15T15:30:00Z', physicalAddress: { description: 'c', - locality: 'd' - } - } - ] - } + locality: 'd', + }, + }, + ], + }, } displayEvents({ data, document, list }) t.is(list.children.length, 3) @@ -51,29 +51,29 @@ test('#displayEvents one event', t => { t.is(list.children[2].childNodes[4].nodeValue, 'c, d') }) -test('#displayErrorMessage no children added', t => { +test('#displayErrorMessage no children added', (t) => { const list = t.context.list displayErrorMessage({ data: '', list }) t.is(list.children.length, 2) }) -test('#displayErrorMessage error message display', t => { +test('#displayErrorMessage error message display', (t) => { const list = t.context.list displayErrorMessage({ data: '', list }) t.is(list.children[0].style.display, 'block') t.is(list.children[1].style.display, 'none') }) -test('#displayErrorMessage group not found error message display', t => { +test('#displayErrorMessage group not found error message display', (t) => { const list = t.context.list const data = { response: { errors: [ { - code: 'group_not_found' - } - ] - } + code: 'group_not_found', + }, + ], + }, } displayErrorMessage({ data, list }) t.is(list.children[0].style.display, 'none') diff --git a/source/connector-mobilizon/front/events-displayer.js b/source/connector-mobilizon/front/events-displayer.js index 3cd4888..a30ceae 100644 --- a/source/connector-mobilizon/front/events-displayer.js +++ b/source/connector-mobilizon/front/events-displayer.js @@ -5,13 +5,21 @@ export function displayEvents({ data, document, list }) { const locale = list.getAttribute('data-locale') const maxEventsCount = list.getAttribute('data-maximum') const timeZone = list.getAttribute('data-time-zone') - const isShortOffsetNameShown = list.hasAttribute('data-is-short-offset-name-shown') - const events = data.events ? data.events.elements : data.group.organizedEvents.elements + const isShortOffsetNameShown = list.hasAttribute( + 'data-is-short-offset-name-shown' + ) + const events = data.events + ? data.events.elements + : data.group.organizedEvents.elements const eventsCount = Math.min(maxEventsCount, events.length) for (let i = 0; i < eventsCount; i++) { const li = document.createElement('li') - const a = createAnchorElement({ document, text: events[i].title, url: events[i].url }) + const a = createAnchorElement({ + document, + text: events[i].title, + url: events[i].url, + }) li.appendChild(a) const br = document.createElement('br') @@ -30,7 +38,7 @@ export function displayEvents({ data, document, list }) { if (events[i].physicalAddress) { const location = Formatter.formatLocation({ description: events[i].physicalAddress.description, - locality: events[i].physicalAddress.locality + locality: events[i].physicalAddress.locality, }) if (location) { const brBeforeLocation = document.createElement('br') @@ -47,11 +55,13 @@ export function displayEvents({ data, document, list }) { export function displayErrorMessage({ data, list }) { console.error(data) - if (Object.prototype.hasOwnProperty.call(data, 'response') && + if ( + Object.prototype.hasOwnProperty.call(data, 'response') && Object.prototype.hasOwnProperty.call(data.response, 'errors') && data.response.errors.length > 0 && Object.prototype.hasOwnProperty.call(data.response.errors[0], 'code') && - data.response.errors[0].code === 'group_not_found') { + data.response.errors[0].code === 'group_not_found' + ) { list.children[1].style.display = 'block' } else { list.children[0].style.display = 'block' diff --git a/source/connector-mobilizon/front/formatter-test.js b/source/connector-mobilizon/front/formatter-test.js index 07653ea..e1959c6 100644 --- a/source/connector-mobilizon/front/formatter-test.js +++ b/source/connector-mobilizon/front/formatter-test.js @@ -1,37 +1,51 @@ import test from 'ava' import Formatter from './formatter' -test('#formatDate one date', t => { - const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z' }) +test('#formatDate one date', (t) => { + const date = Formatter.formatDate({ + start: '2021-04-15T10:30:00Z', + end: '2021-04-15T15:30:00Z', + }) t.is(date, '15/04/2021 10:30 - 15:30') }) -test('#formatDate one date with short offset name', t => { - const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-15T15:30:00Z', isShortOffsetNameShown: true }) +test('#formatDate one date with short offset name', (t) => { + const date = Formatter.formatDate({ + start: '2021-04-15T10:30:00Z', + end: '2021-04-15T15:30:00Z', + isShortOffsetNameShown: true, + }) t.is(date, '15/04/2021 10:30 - 15:30 (UTC)') }) -test('#formatDate two dates', t => { - const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z' }) +test('#formatDate two dates', (t) => { + const date = Formatter.formatDate({ + start: '2021-04-15T10:30:00Z', + end: '2021-04-16T15:30:00Z', + }) t.is(date, '15/04/2021 10:30 - 16/04/2021 15:30') }) -test('#formatDate two dates with short offset name', t => { - const date = Formatter.formatDate({ start: '2021-04-15T10:30:00Z', end: '2021-04-16T15:30:00Z', isShortOffsetNameShown: true }) +test('#formatDate two dates with short offset name', (t) => { + const date = Formatter.formatDate({ + start: '2021-04-15T10:30:00Z', + end: '2021-04-16T15:30:00Z', + isShortOffsetNameShown: true, + }) t.is(date, '15/04/2021 10:30 (UTC) - 16/04/2021 15:30 (UTC)') }) -test('#formatLocation both parameters', t => { +test('#formatLocation both parameters', (t) => { const date = Formatter.formatLocation({ description: 'a', locality: 'b' }) t.is(date, 'a, b') }) -test('#formatLocation description only', t => { +test('#formatLocation description only', (t) => { const date = Formatter.formatLocation({ description: 'a' }) t.is(date, 'a') }) -test('#formatLocation locality only', t => { +test('#formatLocation locality only', (t) => { const date = Formatter.formatLocation({ locality: 'a' }) t.is(date, 'a') }) diff --git a/source/connector-mobilizon/front/formatter.js b/source/connector-mobilizon/front/formatter.js index 996a289..279d4b0 100644 --- a/source/connector-mobilizon/front/formatter.js +++ b/source/connector-mobilizon/front/formatter.js @@ -1,9 +1,12 @@ import DateTimeWrapper from './date-time-wrapper' export default class Formatter { - static formatDate({ locale, timeZone, start, end, isShortOffsetNameShown }) { - const startDateTime = new DateTimeWrapper({ locale, text: start, timeZone }) + const startDateTime = new DateTimeWrapper({ + locale, + text: start, + timeZone, + }) const endDateTime = new DateTimeWrapper({ locale, text: end, timeZone }) let dateText = startDateTime.getShortDate() dateText += ' ' + startDateTime.get24Time() diff --git a/source/connector-mobilizon/front/graphql-wrapper.js b/source/connector-mobilizon/front/graphql-wrapper.js index 658633d..a17fa26 100644 --- a/source/connector-mobilizon/front/graphql-wrapper.js +++ b/source/connector-mobilizon/front/graphql-wrapper.js @@ -21,14 +21,18 @@ export function getUpcomingEvents({ url, limit }) { } } ` - const dataInCache = SessionCache.get(sessionStorage, { url, query, variables: { limit }}) - if (dataInCache !== null) + const dataInCache = SessionCache.get(sessionStorage, { + url, + query, + variables: { limit }, + }) + if (dataInCache !== null) { return Promise.resolve(dataInCache) - return request(url, query, { limit }) - .then((data) => { - SessionCache.add(sessionStorage, { url, query, variables: { limit }}, data) - return Promise.resolve(data) - }) + } + return request(url, query, { limit }).then((data) => { + SessionCache.add(sessionStorage, { url, query, variables: { limit } }, data) + return Promise.resolve(data) + }) } export function getUpcomingEventsByGroupName({ url, limit, groupName }) { @@ -53,12 +57,22 @@ export function getUpcomingEventsByGroupName({ url, limit, groupName }) { } ` const afterDatetime = DateTimeWrapper.getCurrentDatetimeAsString() - const dataInCache = SessionCache.get(sessionStorage, { url, query, variables: { afterDatetime, groupName, limit }}) - if (dataInCache !== null) + const dataInCache = SessionCache.get(sessionStorage, { + url, + query, + variables: { afterDatetime, groupName, limit }, + }) + if (dataInCache !== null) { return Promise.resolve(dataInCache) - return request(url, query, { afterDatetime, groupName, limit }) - .then((data) => { - SessionCache.add(sessionStorage, { url, query, variables: { afterDatetime, groupName, limit }}, data) + } + return request(url, query, { afterDatetime, groupName, limit }).then( + (data) => { + SessionCache.add( + sessionStorage, + { url, query, variables: { afterDatetime, groupName, limit } }, + data + ) return Promise.resolve(data) - }) + } + ) } diff --git a/source/connector-mobilizon/front/html-creator-test.js b/source/connector-mobilizon/front/html-creator-test.js index 4d778df..e17f06f 100644 --- a/source/connector-mobilizon/front/html-creator-test.js +++ b/source/connector-mobilizon/front/html-creator-test.js @@ -9,7 +9,7 @@ test.beforeEach(() => { document = new JSDOM().window.document }) -test('#createAnchorElement usual parameters', t => { +test('#createAnchorElement usual parameters', (t) => { const a = createAnchorElement({ document, text: 'a', url: 'b' }) t.is(a.tagName, 'A') t.is(a.innerHTML, 'a') diff --git a/source/connector-mobilizon/front/object-hash-wrapper-test.js b/source/connector-mobilizon/front/object-hash-wrapper-test.js index 554a9b6..db3740f 100644 --- a/source/connector-mobilizon/front/object-hash-wrapper-test.js +++ b/source/connector-mobilizon/front/object-hash-wrapper-test.js @@ -1,6 +1,6 @@ import test from 'ava' import hash from './object-hash-wrapper' -test('#hash object', t => { - t.is(hash({foo: 'bar'}), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b') +test('#hash object', (t) => { + t.is(hash({ foo: 'bar' }), 'a75c05bdca7d704bdfcd761913e5a4e4636e956b') }) diff --git a/source/connector-mobilizon/front/session-cache-test.js b/source/connector-mobilizon/front/session-cache-test.js index 9baf4c4..e15f421 100644 --- a/source/connector-mobilizon/front/session-cache-test.js +++ b/source/connector-mobilizon/front/session-cache-test.js @@ -2,7 +2,6 @@ import test from 'ava' import SessionCache from './session-cache' const fakeStorage = { - elements: {}, clear() { @@ -17,18 +16,18 @@ const fakeStorage = { setItem(key, value) { this.elements[key] = value - } + }, } test.afterEach(() => { fakeStorage.clear() }) -test('#add & #get', t => { +test('#add & #get', (t) => { SessionCache.add(fakeStorage, { a: 'b' }, { c: 'd' }) t.deepEqual(SessionCache.get(fakeStorage, { a: 'b' }), { c: 'd' }) }) -test('#get no entry', t => { +test('#get no entry', (t) => { t.is(SessionCache.get(fakeStorage, { a: 'bb' }), null) }) diff --git a/source/connector-mobilizon/front/session-cache.js b/source/connector-mobilizon/front/session-cache.js index b23b17a..b136fdb 100644 --- a/source/connector-mobilizon/front/session-cache.js +++ b/source/connector-mobilizon/front/session-cache.js @@ -3,7 +3,6 @@ import hash from './object-hash-wrapper' const MAX_AGE_IN_MS = 120000 export default class SessionCache { - static add(storage, parameters, data) { const key = hash(parameters) const timestamp = Date.now() @@ -17,7 +16,11 @@ export default class SessionCache { static get(storage, parameters) { const key = hash(parameters) const value = JSON.parse(storage.getItem(key)) - if (value && value.timestamp && value.timestamp > Date.now() - MAX_AGE_IN_MS) + if ( + value && + value.timestamp && + value.timestamp > Date.now() - MAX_AGE_IN_MS + ) return value.data return null } diff --git a/webpack.config.js b/webpack.config.js index d04bb89..0286ff6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,10 +1,11 @@ -const path = require('path'); +/* eslint-disable no-undef */ +const path = require('path') -const CopyPlugin = require('copy-webpack-plugin'); +const CopyPlugin = require('copy-webpack-plugin') -const PACKAGE = require('./package.json'); +const PACKAGE = require('./package.json') -const FOLDER_SOURCE = './source'; +const FOLDER_SOURCE = './source' module.exports = { entry: FOLDER_SOURCE + '/' + PACKAGE.name + '/front/events-loader.js', @@ -28,4 +29,4 @@ module.exports = { ], }), ], -}; +}