From 7b69d16efbb44923f2570ce08683fe99f69f4f53 Mon Sep 17 00:00:00 2001 From: Johan Fagerberg Date: Thu, 16 Jan 2020 11:40:46 +0100 Subject: [PATCH] Add CI step for ensuring alphabetical order of icons (#2334) * Add a script for the linting that cannot be accomplished by our other linters Currently this only contains linting for whether our icons are alphabetically sorted * Add our own linting to Travis * Fix Let's Encrypt being incorrectly sorted * Intentionally break sorting to test CI * Revert "Intentionally break sorting to test CI" This reverts commit 55e4070b3c3294cff306fcc138ce247843130c35. * Explain in CONTRIBUTION.md how to sort metadata --- .travis.yml | 1 + CONTRIBUTING.md | 2 ++ _data/simple-icons.json | 10 +++++----- package.json | 1 + scripts/lint.js | 43 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 scripts/lint.js diff --git a/.travis.yml b/.travis.yml index c5cf27cf..47f809a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ jobs: - npm run jsonlint - npm run svglint - npm run wslint + - npm run our-lint - name: "Build website" language: ruby rvm: 2.4.1 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b917f40c..bf8443c6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -145,6 +145,8 @@ Here is the object for The Movie Database as an example: } ``` +Make sure the icon is added in alphabetical order. If you're in doubt, you can always run `npm run our-lint` - this will tell you if any of the JSON data is in the wrong order. + ### 7. Create a pull request Once you've completed the previous steps, create a pull request to merge your edits into the *develop* branch. diff --git a/_data/simple-icons.json b/_data/simple-icons.json index 7167332c..9b32ce51 100644 --- a/_data/simple-icons.json +++ b/_data/simple-icons.json @@ -2495,16 +2495,16 @@ "hex": "E2231A", "source": "https://www.lenovopartnernetwork.com/us/branding/" }, - { - "title": "Letterboxd", - "hex": "00D735", - "source": "https://letterboxd.com/about/logos/" - }, { "title": "Let’s Encrypt", "hex": "003A70", "source": "https://letsencrypt.org/trademarks/" }, + { + "title": "Letterboxd", + "hex": "00D735", + "source": "https://letterboxd.com/about/logos/" + }, { "title": "LGTM", "hex": "FFFFFF", diff --git a/package.json b/package.json index a3f92c04..466ffcd1 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "scripts": { "build": "node scripts/build-package.js", "clean": "rm icons/*.js index.js", + "our-lint": "node scripts/lint.js", "jsonlint": "jsonlint _data/simple-icons.json -q -V .jsonlintschema", "svglint": "svglint icons/* --ci", "wslint": "editorconfig-checker -exclude *.svg", diff --git a/scripts/lint.js b/scripts/lint.js new file mode 100644 index 00000000..f8961634 --- /dev/null +++ b/scripts/lint.js @@ -0,0 +1,43 @@ +#!/usr/bin/env node +/** + * @fileoverview Lints for the package that can't be implemented in the existing linters (e.g. jsonlint/svglint) + */ + +const { icons } = require("../_data/simple-icons.json"); + +/** + * Contains our tests so they can be isolated from eachother; I don't think each test is worth its own file + * @type {{[k:string]: () => (string|undefined)}} + */ +const TESTS = { + /** Tests whether our icons are in alphabetical order */ + alphabetical: function() { + const collector = (invalidEntries, icon, index, array) => { + if (index > 0) { + const prev = array[index - 1]; + if (icon.title.localeCompare(prev.title) < 0) { + invalidEntries.push(icon); + } + } + return invalidEntries; + }; + + const invalids = icons.reduce(collector, []); + if (invalids.length) { + return `Some icons aren't in alphabetical order: + ${invalids.map(icon => icon.title).join(", ")}`; + } + } +}; + +// execute all tests and log potential errors +const errors = Object.keys(TESTS) + .map(k => TESTS[k]()) + .filter(Boolean); + +if (errors.length) { + errors.forEach(error => { + console.error(`\u001b[31m${error}\u001b[0m`); + }); + process.exit(1); +}