Skip to content

Commit

Permalink
Lint JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Nov 14, 2024
1 parent ef86a56 commit c62dcdf
Show file tree
Hide file tree
Showing 39 changed files with 90 additions and 41 deletions.
1 change: 1 addition & 0 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const process = require('node:process')

const rssPlugin = require('@11ty/eleventy-plugin-rss')

module.exports = function (eleventyConfig) {
Expand Down
14 changes: 9 additions & 5 deletions lib/collections/ordered.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ module.exports = (collection) =>
) {
// Sort by order value, if given
return (a.data.order || 0) - (b.data.order || 0)
} else {
// Sort by title
if (a.data.title < b.data.title) return -1
else if (a.data.title > b.data.title) return 1
else return 0
}

// Sort by title
if (a.data.title < b.data.title) {
return -1
} else if (a.data.title > b.data.title) {
return 1
}

return 0
})
26 changes: 12 additions & 14 deletions lib/collections/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ module.exports = (collection) => {
// Add any new tags from the post to the array
for (const tag of item.data.tags) {
// Skip if tag already added
if (tags.includes(tag)) {
continue
}

// Check there’s not a matching tag, except for capitalisation
const existingTag = tags.find(
(existingTag) => existingTag.toLowerCase() === tag.toLowerCase()
)
if (existingTag) {
throw new Error(
`The post ‘${item.data.title}’ contains tag ‘${tag}’ which matches ‘${existingTag}’, but the capitalisation is different.`
if (!tags.includes(tag)) {
// Check there’s not a matching tag, except for capitalisation
const existingTag = tags.find(
(existingTag) => existingTag.toLowerCase() === tag.toLowerCase()
)
}
if (existingTag) {
throw new Error(
`The post ‘${item.data.title}’ contains tag ‘${tag}’ which matches ‘${existingTag}’, but the capitalisation is different.`
)
}

// Otherwise add new tag
tags.push(tag)
// Otherwise add new tag
tags.push(tag)
}
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions lib/data/eleventy-computed.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Get navigation key for page
* @param {object} data Page data
*
* @param {object} data - Page data
* @returns {string|undefined} Page navigation key
*/
const getKey = (data) => {
Expand All @@ -17,7 +18,8 @@ const getKey = (data) => {

/**
* Get navigation parent for page
* @param {object} data Page data
*
* @param {object} data - Page data
* @returns {string|undefined} Parent page key
*/
const getParent = (data) => {
Expand All @@ -34,6 +36,7 @@ const getParent = (data) => {

/**
* Set sensible defaults for eleventyNavigation
*
* @see {@link https://www.11ty.dev/docs/plugins/navigation/}
*/
module.exports = {
Expand Down
1 change: 1 addition & 0 deletions lib/data/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const deepmerge = require('deepmerge')

/**
* Default option values
*
* @see {@link https://x-govuk.github.io/govuk-eleventy-plugin/options/}
*/
const defaultOptions = {
Expand Down
9 changes: 6 additions & 3 deletions lib/events/generate-govuk-assets.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const path = require('node:path')
const fs = require('node:fs/promises')
const sass = require('sass')
const rollup = require('rollup')
const path = require('node:path')

const commonJs = require('@rollup/plugin-commonjs')
const { nodeResolve } = require('@rollup/plugin-node-resolve')
const rollup = require('rollup')
const sass = require('sass')

const { getScssSettings } = require('../utils.js')

/**
* Generate GOV.UK Frontend assets
*
* @param {object} dir - Project directories
* @param {object} pathPrefix - Path prefix
* @param {object} options - Plugin options
Expand Down
1 change: 1 addition & 0 deletions lib/extensions/scss.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('node:path')

const sass = require('sass')

module.exports = {
Expand Down
1 change: 1 addition & 0 deletions lib/filters/canonical-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('node:path')

/**
* Get canonical site URL with resolved path
*
* @param {string} string - Path to resolve
* @returns {string} Canonical site URL with resolved path
*/
Expand Down
1 change: 1 addition & 0 deletions lib/filters/current-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Indicate which is the current item in navigation items
*
* @param {Array} array - Navigation items
* @param {string} pageUrl - URL of current page
* @returns {Array} Navigation items
Expand Down
1 change: 1 addition & 0 deletions lib/filters/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { DateTime } = require('luxon')

/**
* Format a data using tokens
*
* @param {string} string - Date to convert
* @param {string} [format] - Optional token-based formatting
* @returns {string} Formatted date
Expand Down
7 changes: 4 additions & 3 deletions lib/filters/includes.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* Select objects in array whose key includes a value
* @param {Array} array Array to filter
* @param {string} keyPath Key to inspect
* @param {string} value Value key needs to include
*
* @param {Array} array - Array to filter
* @param {string} keyPath - Key to inspect
* @param {string} value - Value key needs to include
* @returns {Array} Filtered array
*/
module.exports = (array, keyPath, value) =>
Expand Down
1 change: 1 addition & 0 deletions lib/filters/items-from-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const smart = require('./smart.js')
/**
* Transform list of posts in a collection to `items` array that can be
* consumed by GOV.UK Frontend components
*
* @param {Array} array - Eleventy collection data
* @returns {Array} `items` array
*/
Expand Down
1 change: 1 addition & 0 deletions lib/filters/items-from-navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const smart = require('./smart.js')
/**
* Transform Eleventy navigation data to `items` array that can be
* consumed by GOV.UK Frontend `govukBreadcrumb` component
*
* @param {Array} eleventyNavigation - Eleventy navigation data
* @param {string} [pageUrl] - URL of current page
* @param {object} [options] - Plugin options
Expand Down
1 change: 1 addition & 0 deletions lib/filters/items-from-pagination.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Transform Eleventy pagination data to `items` array that can be
* consumed by GOV.UK Frontend `govukPagination` component
*
* @param {Array} pagination - Eleventy pagination data
* @returns {Array} `items` array
*/
Expand Down
1 change: 1 addition & 0 deletions lib/filters/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { normalise } = require('../utils.js')

/**
* Convert Markdown into GOV.UK Frontend-compliant HTML
*
* @param {string} string - Markdown string
* @param {string} value - If `inline`, renders HTML without paragraph tags
* @returns {string} HTML
Expand Down
1 change: 1 addition & 0 deletions lib/filters/no-orphans.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { normalise } = require('../utils.js')
/**
* Insert non-breaking space between last two words of a string. This prevents
* an orphaned word appearing by itself at the end of a paragraph.
*
* @param {string} string - Value to transform
* @returns {string} `string` with non-breaking space inserted
* @example
Expand Down
1 change: 1 addition & 0 deletions lib/filters/pretty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Remove (index).html from a string
*
* @see {@link https://www.w3.org/Provider/Style/URI.html}
* @param {string} string - URL, i.e. /page/index.html
* @returns {string} Permalink URL, i.e. /page/
Expand Down
4 changes: 3 additions & 1 deletion lib/filters/smart.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { normalise } = require('../utils.js')
const smartypants = require('smartypants')

const { normalise } = require('../utils.js')

/**
* Convert ASCII punctuation characters into ‘smart’ typographic equivalents
*
* @param {string} string - Value to transform
* @returns {string} `string` with smart typographic punctuation
* @example
Expand Down
1 change: 1 addition & 0 deletions lib/filters/tokenize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Reduce size of a string by removing duplicate and common words
*
* @see {@link https://www.hawksworx.com/blog/adding-search-to-a-jamstack-site}
* @param {string} string - Original string
* @returns {string} Tokenised string
Expand Down
1 change: 1 addition & 0 deletions lib/govuk.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { initAll as GOVUKFrontend } from 'govuk-frontend'

import { SiteSearchElement } from '../components/site-search/site-search.js'

// Initiate custom elements
Expand Down
1 change: 1 addition & 0 deletions lib/markdown-it.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const anchor = require('markdown-it-anchor')

/**
* Configure markdown-it
*
* @see {@link https://markdown-it.github.io/markdown-it/}
* @param {object} [options] - Plugin options
* @returns {Function} markdown-it instance
Expand Down
1 change: 1 addition & 0 deletions lib/markdown-it/deflist.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Render a definition list
*
* @param {Function} md - markdown-it instance
*/
module.exports = function defList(md) {
Expand Down
1 change: 1 addition & 0 deletions lib/markdown-it/footnote.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Render footnotes
*
* @param {Function} md - markdown-it instance
*/
module.exports = function footnotes(md) {
Expand Down
1 change: 1 addition & 0 deletions lib/markdown-it/table-of-contents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Render a table of contents
*
* @param {Function} md - markdown-it instance
*/
module.exports = function contentsList(md) {
Expand Down
1 change: 1 addition & 0 deletions lib/markdown-it/table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Render a table with `tabindex` to enable keyboard scrolling
*
* @param {Function} md - markdown-it instance
*/
module.exports = function table(md) {
Expand Down
4 changes: 4 additions & 0 deletions lib/nunjucks.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const fs = require('node:fs')
const path = require('node:path')

const Nunjucks = require('nunjucks')

/**
* If there is a version conflict between a govuk-eleventy-plugin dependency
* and the host project's dependencies, npm will include the expected version
* in a nested node_modules folder.
*
* @param {string} module - Module name
* @returns {string} Path to module
*/
Expand All @@ -16,6 +18,7 @@ const resolveNpmModule = (module) => {

/**
* Configure Nunjucks environment
*
* @see {@link https://mozilla.github.io/nunjucks/api.html#environment}
* @param {object} eleventyConfig - Eleventy config
* @returns {Function} Nunjucks environment
Expand All @@ -36,6 +39,7 @@ module.exports = (eleventyConfig) => {

/**
* Set default options, but respect `nunjucksEnvironmentOptions`
*
* @see {@link https://www.11ty.dev/docs/languages/nunjucks/#optional-use-your-nunjucks-environment-options}
*/
const options = {
Expand Down
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const path = require('node:path')
const fs = require('node:fs/promises')
const path = require('node:path')

/**
* Read contents of SCSS settings file
*
* @param {object} dir - Eleventy directories
* @param {object} options - Plugin options
* @returns {Promise<string>} SCSS file contents
Expand Down Expand Up @@ -30,6 +31,7 @@ const getScssSettings = async (dir, options) => {
/**
* Normalise value provided to a filter. Checks that a given value exists
* before performing a transformation.
*
* @param {*} value - Input value
* @param {*} defaultValue - Value to fallback to if no value given
* @returns {*} defaultValue
Expand Down
4 changes: 3 additions & 1 deletion test/lib/filters/canonical-url.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const nunjucks = require('nunjucks')

const canonicalUrl = require('../../../lib/filters/canonical-url.js')

describe('canonicalUrl filter', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/current-page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const currentPage = require('../../../lib/filters/current-page.js')

const navigationData = [
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/date.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const date = require('../../../lib/filters/date.js')

describe('Date filter', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/items-from-collection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const itemsFromCollection = require('../../../lib/filters/items-from-collection.js')

const collectionData = [
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/items-from-navigation.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const itemsFromNavigation = require('../../../lib/filters/items-from-navigation.js')

const eleventyNavigationBreadcrumb = [
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/markdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const markdown = require('../../../lib/filters/markdown.js')

describe('markdown filter', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/no-orphans.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const noOrphans = require('../../../lib/filters/no-orphans.js')

describe('noOrphans filter', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/pretty.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const pretty = require('../../../lib/filters/pretty.js')

describe('pretty filter', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/smart.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const smart = require('../../../lib/filters/smart.js')

describe('smart filter', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/lib/filters/tokenize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const assert = require('assert/strict')
const assert = require('node:assert/strict')
const { describe, it } = require('node:test')

const tokenize = require('../../../lib/filters/tokenize.js')

describe('tokenize filter', () => {
Expand Down
Loading

0 comments on commit c62dcdf

Please sign in to comment.