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); +}