Skip to content

Commit

Permalink
[MegaLinter] Apply linters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wesley-dean-gsa authored and megalinter-bot committed Aug 5, 2024
1 parent 7378354 commit d782e55
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 164 deletions.
107 changes: 56 additions & 51 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
const { DateTime } = require('luxon');
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
const pluginRss = require('@11ty/eleventy-plugin-rss');
const pluginNavigation = require('@11ty/eleventy-navigation');
const markdownIt = require('markdown-it');
const markdownItAnchor = require('markdown-it-anchor');
const { DateTime } = require("luxon");
const esbuild = require("esbuild");
const fs = require("fs");
const path = require("path");
const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginNavigation = require("@11ty/eleventy-navigation");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const yaml = require("js-yaml");
const { sassPlugin } = require('esbuild-sass-plugin');
const { sassPlugin } = require("esbuild-sass-plugin");
const svgSprite = require("eleventy-plugin-svg-sprite");
const { imageShortcode, imageWithClassShortcode } = require('./config');
const { imageShortcode, imageWithClassShortcode } = require("./config");

module.exports = function (config) {
// Set pathPrefix for site
let pathPrefix = '/';
let pathPrefix = "/";
// Copy the `admin` folders to the output
config.addPassthroughCopy('admin');
config.addPassthroughCopy("admin");

// for #80 (update site favicon)
// copy files from `_img/favicon/` to `_site/`
config.addPassthroughCopy({ "_img/favicon/favicon.ico": "/assets/favicon.ico" });
config.addPassthroughCopy({
"_img/favicon/favicon.ico": "/assets/favicon.ico",
});

// Copy USWDS init JS so we can load it in HEAD to prevent banner flashing
config.addPassthroughCopy({'./node_modules/@uswds/uswds/dist/js/uswds-init.js': 'assets/js/uswds-init.js'});
config.addPassthroughCopy({
"./node_modules/@uswds/uswds/dist/js/uswds-init.js":
"assets/js/uswds-init.js",
});

// Add plugins
config.addPlugin(pluginRss);
Expand All @@ -31,23 +36,23 @@ module.exports = function (config) {
//// SVG Sprite Plugin for USWDS USWDS icons
config.addPlugin(svgSprite, {
path: "./node_modules/@uswds/uswds/dist/img/uswds-icons",
svgSpriteShortcode: 'uswds_icons_sprite',
svgShortcode: 'uswds_icons'
svgSpriteShortcode: "uswds_icons_sprite",
svgShortcode: "uswds_icons",
});

//// SVG Sprite Plugin for USWDS USA icons
config.addPlugin(svgSprite, {
path: "./node_modules/@uswds/uswds/dist/img/usa-icons",
svgSpriteShortcode: 'usa_icons_sprite',
svgShortcode: 'usa_icons'
svgSpriteShortcode: "usa_icons_sprite",
svgShortcode: "usa_icons",
});

// Allow yaml to be used in the _data dir
config.addDataExtension("yaml", contents => yaml.load(contents));
config.addDataExtension("yaml", (contents) => yaml.load(contents));

// This is an example of creating an Eleventy collection from
// a data file, in this case it's _data/services.yml
config.addCollection('services', (collection) => {
config.addCollection("services", (collection) => {
const allServices = collection.getAll()[0].data.services;
return allServices;
});
Expand All @@ -57,29 +62,29 @@ module.exports = function (config) {
function sortByProp(values, prop) {
let vals = [...values];
return vals.sort((a, b) => {
if (typeof a[prop] == 'string' && typeof b[prop] == 'string') {
if (typeof a[prop] == "string" && typeof b[prop] == "string") {
return a[prop].localeCompare(b[prop]);
} else {
return Math.sign(a[prop] - b[prop]);
}
});
}

config.addFilter('sortByProp', sortByProp);
config.addFilter("sortByProp", sortByProp);

config.addFilter('readableDate', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat(
'dd LLL yyyy'
config.addFilter("readableDate", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat(
"dd LLL yyyy",
);
});

// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
config.addFilter('htmlDateString', (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: 'utc' }).toFormat('yyyy-LL-dd');
config.addFilter("htmlDateString", (dateObj) => {
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat("yyyy-LL-dd");
});

// Get the first `n` elements of a collection.
config.addFilter('head', (array, n) => {
config.addFilter("head", (array, n) => {
if (!Array.isArray(array) || array.length === 0) {
return [];
}
Expand All @@ -91,20 +96,20 @@ module.exports = function (config) {
});

// Return the smallest number argument
config.addFilter('min', (...numbers) => {
config.addFilter("min", (...numbers) => {
return Math.min.apply(null, numbers);
});

function filterTagList(tags) {
return (tags || []).filter(
(tag) => ['all', 'nav', 'post', 'posts'].indexOf(tag) === -1
(tag) => ["all", "nav", "post", "posts"].indexOf(tag) === -1,
);
}

config.addFilter('filterTagList', filterTagList);
config.addFilter("filterTagList", filterTagList);

// Create an array of all tags
config.addCollection('tagList', function (collection) {
config.addCollection("tagList", function (collection) {
let tagSet = new Set();
collection.getAll().forEach((item) => {
(item.data.tags || []).forEach((tag) => tagSet.add(tag));
Expand All @@ -120,26 +125,26 @@ module.exports = function (config) {
linkify: true,
}).use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
placement: 'after',
class: 'direct-link',
symbol: '',
placement: "after",
class: "direct-link",
symbol: "",
level: [1, 2, 3, 4],
}),
slugify: config.getFilter('slug'),
slugify: config.getFilter("slug"),
});
config.setLibrary('md', markdownLibrary);
config.setLibrary("md", markdownLibrary);

// Override Browsersync defaults (used only with --serve)
config.setBrowserSyncConfig({
callbacks: {
ready: function (err, browserSync) {
const content_404 = fs.readFileSync('_site/404/index.html');
const content_404 = fs.readFileSync("_site/404/index.html");

browserSync.addMiddleware('*', (req, res) => {
browserSync.addMiddleware("*", (req, res) => {
// Provides the 404 content without redirect.
res.writeHead(404, { 'Content-Type': 'text/html; charset=UTF-8' });
res.writeHead(404, { "Content-Type": "text/html; charset=UTF-8" });
res.write(content_404);
const svgSprite = require("eleventy-plugin-svg-sprite");
const svgSprite = require("eleventy-plugin-svg-sprite");
res.end();
});
},
Expand All @@ -149,8 +154,8 @@ const svgSprite = require("eleventy-plugin-svg-sprite");
});

// Set image shortcodes
config.addLiquidShortcode('image', imageShortcode);
config.addLiquidShortcode('image_with_class', imageWithClassShortcode);
config.addLiquidShortcode("image", imageShortcode);
config.addLiquidShortcode("image_with_class", imageWithClassShortcode);
config.addLiquidShortcode("uswds_icon", function (name) {
return `
<svg class="usa-icon" aria-hidden="true" role="img">
Expand All @@ -168,25 +173,25 @@ const svgSprite = require("eleventy-plugin-svg-sprite");

// If BASEURL env variable exists, update pathPrefix to the BASEURL
if (process.env.BASEURL) {
pathPrefix = process.env.BASEURL
pathPrefix = process.env.BASEURL;
}

return {
dataTemplateEngine: "liquid",

// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: ['md', 'njk', 'html', 'liquid'],
templateFormats: ["md", "njk", "html", "liquid"],

// Pre-process *.md files with: (default: `liquid`)
// Other template engines are available
// See https://www.11ty.dev/docs/languages/ for other engines.
markdownTemplateEngine: 'liquid',
markdownTemplateEngine: "liquid",

// Pre-process *.html files with: (default: `liquid`)
// Other template engines are available
// See https://www.11ty.dev/docs/languages/ for other engines.
htmlTemplateEngine: 'liquid',
htmlTemplateEngine: "liquid",

// -----------------------------------------------------------------
// If your site deploys to a subdirectory, change `pathPrefix`.
Expand All @@ -204,10 +209,10 @@ const svgSprite = require("eleventy-plugin-svg-sprite");

// These are all optional (defaults are shown):
dir: {
input: '.',
includes: '_includes',
data: '_data',
output: '_site',
input: ".",
includes: "_includes",
data: "_data",
output: "_site",
},
};
};
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Changes proposed in this pull request:
## Changes proposed in this pull request
-
-
-
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/megalinter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ on:
- main
workflow_dispatch:


permissions:
contents: write
issues: write
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/pa11y.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---
name: Pa11y Testing


# yamllint disable-line rule:truthy
on:
pull_request:
Expand All @@ -22,7 +21,6 @@ jobs:
pull-requests: write

steps:

- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # [email protected]

- name: Install Chrome
Expand All @@ -37,7 +35,7 @@ jobs:
- name: Use Node
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # pin@v3
with:
node-version: '18'
node-version: "18"

- name: Install Pa11y
run: npm install pa11y
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:

# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '43 7 * * 3'
- cron: "43 7 * * 3"
push:
branches:
- "main"
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ name: Build and Test
on:
pull_request:


jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -16,13 +15,12 @@ jobs:
- name: Use Node
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # pin@v3
with:
node-version: '17.x'
node-version: "17.x"

- name: Install NPM dependencies
run: npm install

- name: Build site
run: npm run build

# - name: Run tests
# run: npm run test
9 changes: 4 additions & 5 deletions .grype.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
fail-on-severity: "high"

exclude:
- './node_modules/**'
- './.git/**'
- './.github/**'
- './_site/**'
- "./node_modules/**"
- "./.git/**"
- "./.github/**"
- "./_site/**"

ignore:

# Ignored by default; disputed and unwarranted CVE that causes Megalinter to fail
# @link https://nvd.nist.gov/vuln/detail/CVE-2018-20225
- vulnerability: CVE-2018-20225
9 changes: 2 additions & 7 deletions .mega-linter.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
---
# don't test the reports Mega-Linter created, docs, or test files
ADDITIONAL_EXCLUDED_DIRECTORIES: [
report,
megalinter-reports,
docs,
node_modules,
_site,
]
ADDITIONAL_EXCLUDED_DIRECTORIES:
[report, megalinter-reports, docs, node_modules, _site]

# don't lint test files or documentation
FILTER_REGEX_EXCLUDE: (.venv/|/test/|\.test\.|_test\.|/docs/|/index.html|.github/.*\.html)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Welcome!
# Welcome

We're so glad you're thinking about contributing to a [open source project of the U.S. government](https://code.gov/)! If you're unsure about anything, just ask -- or submit the issue or pull request anyway. The worst that can happen is you'll be politely asked to change something. We love all friendly contributions.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Technology Transformation Services website

This is the code for https://tts.gsa.gov. Our tech stack in short is:
This is the code for <https://tts.gsa.gov>. Our tech stack in short is:

- [11ty](https://www.11ty.dev/)
- [U.S. Web Design System v 3.0 (USWDS)](https://designsystem.digital.gov/)
Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Please consult our policy for:
Please note that only certain branches are supported with security updates.

| Version (Branch) | Supported |
| ---------------- | ------------------ |
|------------------|--------------------|
| main | :white_check_mark: |
| other | :x: |

Expand Down
2 changes: 1 addition & 1 deletion _data/assetPaths.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"uswds.js": "/assets/js/uswds-init.js",
"styles.css": "/assets/styles/styles-J5DQM6RN.css",
"styles.map": "/assets/styles/styles-J5DQM6RN.css.map"
}
}
12 changes: 6 additions & 6 deletions _data/collections.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# We can add any kind of data in this _data folder and this file.
# In this example, we create a simple array of options and then in the _pages/collections.md file we
# Reference this data file in 'datafile' in the Front Matter and _layouts/list.html renders it
# In this example, we create a simple array of options and then in the _pages/collections.md file we
# Reference this data file in 'datafile' in the Front Matter and _layouts/list.html renders it
# This is simple, hopefully provides you with a good enough example to make changes as needed
- name: GSA

Check warning on line 5 in _data/collections.yaml

View workflow job for this annotation

GitHub Actions / MegaLinter

5:1 [document-start] missing document start "---"
url: https://gsa.gov
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.

- name: USDA
url: http://usda.gov/
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.

- name: Performance.gov
url: http://performance.gov/
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.

- name: Login.gov
url: https://login.gov
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec dapibus interdum pellentesque. Integer eu vehicula elit. Sed cursus magna in dui suscipit rhoncus.
Loading

0 comments on commit d782e55

Please sign in to comment.