From de3c3f1f6b06128676ca779b00c0c81a40039607 Mon Sep 17 00:00:00 2001 From: Srijan Saurav <68371686+srijan-deepsource@users.noreply.github.com> Date: Mon, 30 May 2022 16:19:26 +0530 Subject: [PATCH] Revert "chore: lint eleventy config file (#15904)" This reverts commit f4916606d2571baa3517adf67b378313668a9588. --- .eslintignore | 1 - .eslintrc.js | 30 ++--- .github/workflows/ci.yml | 5 - Makefile.js | 26 +--- docs/.eleventy.js | 283 ++++++++++++++++++++------------------- docs/README.md | 12 -- docs/package.json | 3 - package.json | 2 - 8 files changed, 153 insertions(+), 209 deletions(-) diff --git a/.eslintignore b/.eslintignore index 905f2a39ddf..b8414c9c832 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,7 +1,6 @@ /build/** /coverage/** /docs/** -!/docs/.eleventy.js /jsdoc/** /templates/** /tests/bench/** diff --git a/.eslintrc.js b/.eslintrc.js index 4df24ee7349..33d895f5c11 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,7 +46,8 @@ module.exports = { "internal-rules" ], extends: [ - "eslint" + "eslint", + "plugin:eslint-plugin/recommended" ], parserOptions: { ecmaVersion: 2021 @@ -62,6 +63,14 @@ module.exports = { } }, rules: { + "eslint-plugin/prefer-message-ids": "error", + "eslint-plugin/prefer-output-null": "error", + "eslint-plugin/prefer-placeholders": "error", + "eslint-plugin/prefer-replace-text": "error", + "eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"], + "eslint-plugin/require-meta-docs-description": "error", + "eslint-plugin/test-case-property-ordering": "error", + "eslint-plugin/test-case-shorthand-strings": "error", "internal-rules/multiline-comment-style": "error" }, overrides: [ @@ -74,15 +83,7 @@ module.exports = { { files: ["lib/rules/*", "tools/internal-rules/*"], excludedFiles: ["index.js"], - extends: [ - "plugin:eslint-plugin/rules-recommended" - ], rules: { - "eslint-plugin/prefer-message-ids": "error", - "eslint-plugin/prefer-placeholders": "error", - "eslint-plugin/prefer-replace-text": "error", - "eslint-plugin/report-message-format": ["error", "[^a-z].*\\.$"], - "eslint-plugin/require-meta-docs-description": "error", "internal-rules/no-invalid-meta": "error" } }, @@ -93,17 +94,6 @@ module.exports = { "eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/rules/{{name}}" }] } }, - { - files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"], - extends: [ - "plugin:eslint-plugin/tests-recommended" - ], - rules: { - "eslint-plugin/prefer-output-null": "error", - "eslint-plugin/test-case-property-ordering": "error", - "eslint-plugin/test-case-shorthand-strings": "error" - } - }, { files: ["tests/**/*"], env: { mocha: true }, diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a61886ab522..1bbaacfca60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,11 +22,6 @@ jobs: run: node Makefile checkRuleFiles - name: Check Licenses run: node Makefile checkLicenses - - name: Install Docs Packages - working-directory: docs - run: npm install - - name: Lint Docs JS Files - run: node Makefile lintDocsJS test_on_node: name: Test diff --git a/Makefile.js b/Makefile.js index bdd3aca75bc..de786148c65 100644 --- a/Makefile.js +++ b/Makefile.js @@ -482,17 +482,8 @@ target.lint = function([fix = false] = []) { let errors = 0, lastReturn; - /* - * In order to successfully lint JavaScript files in the `docs` directory, dependencies declared in `docs/package.json` - * would have to be installed in `docs/node_modules`. In particular, eslint-plugin-node rules examine `docs/node_modules` - * when analyzing `require()` calls from CJS modules in the `docs` directory. Since our release process does not run `npm install` - * in the `docs` directory, linting would fail and break the release. Also, working on the main `eslint` package does not require - * installing dependencies declared in `docs/package.json`, so most contributors will not have `docs/node_modules` locally. - * Therefore, we add `--ignore-pattern docs` to exclude linting the `docs` directory from this command. - * There is a separate command `target.lintDocsJS` for linting JavaScript files in the `docs` directory. - */ echo("Validating JavaScript files"); - lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} . --ignore-pattern docs`); + lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} .`); if (lastReturn.code !== 0) { errors++; } @@ -511,21 +502,6 @@ target.lint = function([fix = false] = []) { } }; -target.lintDocsJS = function([fix = false] = []) { - let errors = 0; - - echo("Validating JavaScript files in the docs directory"); - const lastReturn = exec(`${ESLINT}${fix ? "--fix" : ""} docs`); - - if (lastReturn.code !== 0) { - errors++; - } - - if (errors) { - exit(1); - } -}; - target.fuzz = function({ amount = 1000, fuzzBrokenAutofixes = false } = {}) { const fuzzerRunner = require("./tools/fuzzer-runner"); const fuzzResults = fuzzerRunner.run({ amount, fuzzBrokenAutofixes }); diff --git a/docs/.eleventy.js b/docs/.eleventy.js index ba0c98d5a34..ecda440722e 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -1,19 +1,19 @@ -"use strict"; - const eleventyNavigationPlugin = require("@11ty/eleventy-navigation"); const syntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); const pluginRss = require("@11ty/eleventy-plugin-rss"); -const pluginTOC = require("eleventy-plugin-nesting-toc"); +const pluginTOC = require('eleventy-plugin-nesting-toc'); const slugify = require("slugify"); -const markdownItAnchor = require("markdown-it-anchor"); +const markdownIt = require("markdown-it"); +const markdownItAnchor = require('markdown-it-anchor'); const Image = require("@11ty/eleventy-img"); -const path = require("path"); +const path = require('path'); const { DateTime } = require("luxon"); module.exports = function(eleventyConfig) { + let now = new Date(); /* * The site is loaded from /docs on eslint.org and so we need to adjust @@ -21,111 +21,109 @@ module.exports = function(eleventyConfig) { * * The path prefix is turned off for deploy previews so we can properly * see changes before deployed. - */ + */ const pathPrefix = process.env.CONTEXT === "deploy-preview" ? "" : "/docs"; - //------------------------------------------------------------------------------ - // Filters - //------------------------------------------------------------------------------ - - eleventyConfig.addFilter("limitTo", (arr, limit) => arr.slice(0, limit)); + /***************************************************************************************** + * Filters + * ***************************************************************************************/ + eleventyConfig.addFilter("limitTo", function(arr, limit) { + return arr.slice(0, limit); + }); - eleventyConfig.addFilter("jsonify", variable => JSON.stringify(variable)); + eleventyConfig.addFilter('jsonify', function(variable) { + return JSON.stringify(variable); + }); - eleventyConfig.addFilter("slugify", str => { + eleventyConfig.addFilter('slugify', function(str) { if (!str) { - return ""; + return; } return slugify(str, { lower: true, strict: true, - remove: /["]/gu + remove: /["]/g, }); }); - eleventyConfig.addFilter("URIencode", str => { + eleventyConfig.addFilter('URIencode', function(str) { if (!str) { - return ""; + return; } return encodeURI(str); }); /* order collection by the order specified in the front matter */ - eleventyConfig.addFilter("sortByPageOrder", values => values.slice().sort((a, b) => a.data.order - b.data.order)); - - eleventyConfig.addFilter("readableDate", dateObj => { - - // turn it into a JS Date string - const date = new Date(dateObj); - - // pass it to luxon for formatting - return DateTime.fromJSDate(date).toFormat("dd MMM, yyyy"); + eleventyConfig.addFilter("sortByPageOrder", function(values) { + return values.slice().sort((a, b) => a.data.order - b.data.order); }); - eleventyConfig.addFilter("blogPermalinkDate", dateObj => { - - // turn it into a JS Date string - const date = new Date(dateObj); + eleventyConfig.addFilter("readableDate", (dateObj) => { + //turn it into a JS Date string + date = new Date(dateObj); + //pass it to luxon for formatting + return DateTime.fromJSDate(date).toFormat('dd MMM, yyyy'); + }); - // pass it to luxon for formatting - return DateTime.fromJSDate(date).toFormat("yyyy/MM"); + eleventyConfig.addFilter("blogPermalinkDate", (dateObj) => { + //turn it into a JS Date string + date = new Date(dateObj); + //pass it to luxon for formatting + return DateTime.fromJSDate(dateObj).toFormat('yyyy/MM'); }); - eleventyConfig.addFilter("readableDateFromISO", ISODate => DateTime.fromISO(ISODate).toUTC().toLocaleString(DateTime.DATE_FULL)); + eleventyConfig.addFilter("readableDateFromISO", (ISODate) => { + return DateTime.fromISO(ISODate).toUTC().toLocaleString(DateTime.DATE_FULL); + }); - eleventyConfig.addFilter("dollars", value => new Intl.NumberFormat("en-US", { - style: "currency", - currency: "USD" - }).format(value)); + eleventyConfig.addFilter('dollars', value => { + return new Intl.NumberFormat("en-US", { + style: "currency", + currency: "USD" + }).format(value); + }); - /* - * parse markdown from includes, used for author bios - * Source: https://github.com/11ty/eleventy/issues/658 - */ - eleventyConfig.addFilter("markdown", value => { - const markdown = require("markdown-it")({ + // parse markdown from includes, used for author bios + // Source: https://github.com/11ty/eleventy/issues/658 + eleventyConfig.addFilter('markdown', function(value) { + let markdown = require('markdown-it')({ html: true }); - return markdown.render(value); }); - //------------------------------------------------------------------------------ - // Plugins - //------------------------------------------------------------------------------ - + /***************************************************************************************** + * Plugins + * ***************************************************************************************/ eleventyConfig.addPlugin(eleventyNavigationPlugin); eleventyConfig.addPlugin(syntaxHighlight, { - alwaysWrapLineHighlights: true + alwaysWrapLineHighlights: true, }); eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPlugin(pluginTOC, { - tags: ["h2", "h3", "h4"], - wrapper: "nav", // Element to put around the root `ol` - wrapperClass: "c-toc", // Class for the element around the root `ol` - headingText: "", // Optional text to show in heading above the wrapper element - headingTag: "h2" // Heading tag when showing heading above the wrapper element + tags: ['h2', 'h3', 'h4'], + wrapper: 'nav', // Element to put around the root `ol` + wrapperClass: 'c-toc', // Class for the element around the root `ol` + headingText: '', // Optional text to show in heading above the wrapper element + headingTag: 'h2' // Heading tag when showing heading above the wrapper element }); - // add IDs to the headers - const markdownIt = require("markdown-it"); - + const markdownIt = require('markdown-it'); eleventyConfig.setLibrary("md", markdownIt({ html: true, linkify: true, - typographer: true - - }).use(markdownItAnchor, {}).disable("code")); + typographer: true, - //------------------------------------------------------------------------------ - // Shortcodes - //------------------------------------------------------------------------------ + }).use(markdownItAnchor, {}).disable('code') + ); + /********************************************************************** + * Shortcodes + * ********************************************************************/ eleventyConfig.addNunjucksShortcode("link", function(url) { - // eslint-disable-next-line no-invalid-this -- Eleventy API const urlData = this.ctx.further_reading_links[url]; if (!urlData) { @@ -153,36 +151,42 @@ module.exports = function(eleventyConfig) { `; }); - eleventyConfig.addShortcode("fixable", () => ` + eleventyConfig.addShortcode("fixable", function() { + return `
🛠 Fixable

if some problems reported by the rule are automatically fixable by the --fix command line option

-
`); + `; + }); - eleventyConfig.addShortcode("recommended", () => ` + eleventyConfig.addShortcode("recommended", function() { + return `
✅ Recommended

if the "extends": "eslint:recommended" property in a configuration file enables the rule.

-
`); + `; + }); - eleventyConfig.addShortcode("hasSuggestions", () => ` + eleventyConfig.addShortcode("hasSuggestions", function() { + return `
💡 hasSuggestions

if some problems reported by the rule are manually fixable by editor suggestions

-
`); + `; + }); - eleventyConfig.addShortcode("related_rules", arr => { - const rules = arr; - let items = ""; + eleventyConfig.addShortcode("related_rules", function(arr) { + let rules = arr, + items = ""; - rules.forEach(rule => { - const listItem = ``; - - items += listItem; - }); + items += list_item; + }) return ` `; }); - eleventyConfig.addShortcode("important", (text, url) => ` + eleventyConfig.addShortcode("important", function(text, url) { + return `
${text}
Learn more
- `); + `; + }); - eleventyConfig.addShortcode("warning", (text, url) => ` + eleventyConfig.addShortcode("warning", function(text, url) { + return `
${text}
Learn more
- `); + `; + }); - eleventyConfig.addShortcode("tip", (text, url) => ` + eleventyConfig.addShortcode("tip", function(text, url) { + return `
${text}
Learn more
- `); + `; + }); eleventyConfig.addWatchTarget("./src/assets/"); - //------------------------------------------------------------------------------ - // File PassThroughs - //------------------------------------------------------------------------------ + + + /***************************************************************************************** + * File PassThroughs + * ***************************************************************************************/ eleventyConfig.addPassthroughCopy({ "./src/static": "/" }); - eleventyConfig.addPassthroughCopy("./src/assets/"); + eleventyConfig.addPassthroughCopy('./src/assets/'); eleventyConfig.addPassthroughCopy({ - "./src/content/**/*.png": "/assets/images" + './src/content/**/*.png': "/assets/images" }); eleventyConfig.addPassthroughCopy({ - "./src/content/**/*.jpg": "/assets/images" + './src/content/**/*.jpg': "/assets/images" }); eleventyConfig.addPassthroughCopy({ - "./src/content/**/*.jpeg": "/assets/images" + './src/content/**/*.jpeg': "/assets/images" }); eleventyConfig.addPassthroughCopy({ - "./src/content/**/*.svg": "/assets/images" + './src/content/**/*.svg': "/assets/images" }); eleventyConfig.addPassthroughCopy({ - "./src/content/**/*.mp4": "/assets/videos" + './src/content/**/*.mp4': "/assets/videos" }); eleventyConfig.addPassthroughCopy({ - "./src/content/**/*.pdf": "/assets/documents" + './src/content/**/*.pdf': "/assets/documents" }); eleventyConfig.addPassthroughCopy({ - "./node_modules/algoliasearch/dist/algoliasearch-lite.esm.browser.js": "/assets/js/algoliasearch.js" + './node_modules/algoliasearch/dist/algoliasearch-lite.esm.browser.js': "/assets/js/algoliasearch.js" }); - //------------------------------------------------------------------------------ - // Collections - //------------------------------------------------------------------------------ + /***************************************************************************************** + * Collections + * ***************************************************************************************/ - eleventyConfig.addCollection("docs", collection => collection.getFilteredByGlob("./src/**/**/*.md")); + eleventyConfig.addCollection("docs", function(collection) { + return collection.getFilteredByGlob("./src/**/**/*.md"); + }); - eleventyConfig.addCollection("library", collection => collection.getFilteredByGlob("./src/library/**/*.md")); + eleventyConfig.addCollection("library", function(collection) { + return collection.getFilteredByGlob("./src/library/**/*.md"); + }); - // START, eleventy-img (https://www.11ty.dev/docs/plugins/image/) - /* eslint-disable-next-line jsdoc/require-jsdoc - -- - This shortcode is currently unused. If we are going to use it, add JSDoc - and describe what exactly is this doing. - */ - function imageShortcode(source, alt, cls, sizes = "(max-width: 768px) 100vw, 50vw") { - const options = { + // START, eleventy-img + function imageShortcode(src, alt, cls, sizes = "(max-width: 768px) 100vw, 50vw") { + const source = src; + + let options = { widths: [600, 900, 1500], formats: ["webp", "jpeg"], urlPath: "/assets/images/", outputDir: "./_site/assets/images/", - filenameFormat(id, src, width, format) { - const extension = path.extname(src); - const name = path.basename(src, extension); - - return `${name}-${width}w.${format}`; + filenameFormat: function(id, src, width, format, options) { + const extension = path.extname(src) + const name = path.basename(src, extension) + return `${name}-${width}w.${format}` } - }; + } - /** - * Resolves source - * @returns {string} URL or a local file path - */ function getSRC() { - if (source.startsWith("http://") || source.startsWith("https://")) { + if (source.indexOf("http://") == 0 || source.indexOf("https://") == 0) { return source; + } else { + // for convenience, you only need to use the image's name in the shortcode, + // and this will handle appending the full path to it + src = path.join('./src/assets/images/', source); + return src; } - - /* - * for convenience, you only need to use the image's name in the shortcode, - * and this will handle appending the full path to it - */ - return path.join("./src/assets/images/", source); } - const fullSrc = getSRC(); - - + var fullSrc = getSRC(); // generate images - Image(fullSrc, options); // eslint-disable-line new-cap -- `Image` is a function + Image(fullSrc, options) - const imageAttributes = { + let imageAttributes = { alt, class: cls, sizes, loading: "lazy", - decoding: "async" - }; - + decoding: "async", + } // get metadata - const metadata = Image.statsSync(fullSrc, options); - - return Image.generateHTML(metadata, imageAttributes); + metadata = Image.statsSync(fullSrc, options) + return Image.generateHTML(metadata, imageAttributes) } - eleventyConfig.addShortcode("image", imageShortcode); - + eleventyConfig.addShortcode("image", imageShortcode) // END, eleventy-img @@ -351,9 +352,9 @@ module.exports = function(eleventyConfig) { pathPrefix, - markdownTemplateEngine: "njk", - dataTemplateEngine: "njk", - htmlTemplateEngine: "njk", + markdownTemplateEngine: 'njk', + dataTemplateEngine: 'njk', + htmlTemplateEngine: 'njk', dir: { input: "src", diff --git a/docs/README.md b/docs/README.md index ee5f64e100e..ac6484a189f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,15 +13,3 @@ To update the links data file, run this from the root folder (not the `docs` fol ```shell npm run docs:update-links ``` - -To lint JS files, run this from the root folder (not the `docs` folder): - -```shell -npm run lint:docsjs -``` - -To autofix JS files, run this from the root folder (not the `docs` folder): - -```shell -npm run fix:docsjs -``` diff --git a/docs/package.json b/docs/package.json index ba963f8e767..aae609e17a2 100644 --- a/docs/package.json +++ b/docs/package.json @@ -1,13 +1,11 @@ { "name": "docs-eslint", - "private": true, "version": "1.0.0", "description": "", "main": "index.js", "keywords": [], "author": "", "license": "ISC", - "files": [], "scripts": { "images": "imagemin '_site/assets/images' --out-dir='_site/assets/images'", "watch:sass": "sass --watch --poll src/assets/scss:src/assets/css", @@ -30,7 +28,6 @@ "eleventy-plugin-reading-time": "^0.0.1", "imagemin": "^8.0.1", "imagemin-cli": "^7.0.0", - "luxon": "^2.4.0", "markdown-it": "^12.2.0", "markdown-it-anchor": "^8.1.2", "netlify-cli": "^10.3.1", diff --git a/package.json b/package.json index f1010b32ace..9a565f2f9e4 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,7 @@ "test": "node Makefile.js test", "test:cli": "mocha", "lint": "node Makefile.js lint", - "lint:docsjs": "node Makefile.js lintDocsJS", "fix": "node Makefile.js lint -- fix", - "fix:docsjs": "node Makefile.js lintDocsJS -- fix", "fuzz": "node Makefile.js fuzz", "generate-release": "node Makefile.js generateRelease", "generate-alpharelease": "node Makefile.js generatePrerelease -- alpha",