From 74b3f1ef6b22a4679fc777634249d655fb3e505d Mon Sep 17 00:00:00 2001 From: Roland Warmerdam Date: Wed, 6 Dec 2017 13:51:02 -0800 Subject: [PATCH] Add prettier --- lib/__tests__/cli.js | 24 ++++++++++++------------ lib/__tests__/index.js | 5 +---- lib/cli.js | 33 ++++++++++++++++++--------------- lib/index.js | 4 ++-- package.json | 28 ++++++++++++---------------- yarn.lock | 12 +++++++++++- 6 files changed, 56 insertions(+), 50 deletions(-) diff --git a/lib/__tests__/cli.js b/lib/__tests__/cli.js index 8d34f6b..3c790a9 100644 --- a/lib/__tests__/cli.js +++ b/lib/__tests__/cli.js @@ -11,13 +11,14 @@ function formatUrls(urls) { test('should extract urls from sitemap file', () => { const sitemapPath = path.join(__dirname, 'fixtures/sitemap.xml') - return execa(CLI, [sitemapPath], {input: '', stripEof: false}).then(result => { - expect(result.stdout).toBe(formatUrls([ - 'http://example.com/', - 'http://example.com/test/' - ])) - expect(result.stderr).toBe('') - }) + return execa(CLI, [sitemapPath], { input: '', stripEof: false }).then( + result => { + expect(result.stdout).toBe( + formatUrls(['http://example.com/', 'http://example.com/test/']) + ) + expect(result.stderr).toBe('') + } + ) }) test('should extract urls from stdin', () => { @@ -35,11 +36,10 @@ test('should extract urls from stdin', () => { ` - return execa(CLI, [], {input: stdin, stripEof: false}).then(result => { - expect(result.stdout).toBe(formatUrls([ - 'http://example.com/', - 'http://example.com/test/' - ])) + return execa(CLI, [], { input: stdin, stripEof: false }).then(result => { + expect(result.stdout).toBe( + formatUrls(['http://example.com/', 'http://example.com/test/']) + ) expect(result.stderr).toBe('') }) }) diff --git a/lib/__tests__/index.js b/lib/__tests__/index.js index 6fe89c9..6d0bf7b 100644 --- a/lib/__tests__/index.js +++ b/lib/__tests__/index.js @@ -18,10 +18,7 @@ describe('#extractUrls', () => { `) - expect(urls).toEqual([ - 'http://example.com/', - 'http://example.com/test/' - ]) + expect(urls).toEqual(['http://example.com/', 'http://example.com/test/']) }) test('should not include duplicate urls', () => { diff --git a/lib/cli.js b/lib/cli.js index e230dcc..99fe4ff 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -8,7 +8,8 @@ const meow = require('meow') const stdin = require('get-stdin') const sitemapUrls = require('../') -const cli = meow(` +const cli = meow( + ` Usage: sitemap-urls [] Path: @@ -18,39 +19,41 @@ Path: Options: -h, --help Show this help text. -v, --version Print sitemap-urls' version. -`, { - flags: { - help: { - type: 'boolean', - alias: 'h' - }, - version: { - type: 'boolean', - alias: 'v' +`, + { + flags: { + help: { + type: 'boolean', + alias: 'h' + }, + version: { + type: 'boolean', + alias: 'v' + } } } -}) +) stdin().then(stdinSitemap => { let filepath let sitemap - // Require stdin or file + // Require stdin or file if (!stdinSitemap && !cli.input[0]) { cli.showHelp() } - // Try reading file if no stdin + // Try reading file if no stdin if (stdinSitemap) { sitemap = stdinSitemap } else { filepath = path.resolve(cli.input[0]) if (!fs.existsSync(filepath) || !fs.statSync(filepath).isFile()) { - console.error('File doesn\'t exist:', filepath) + console.error("File doesn't exist:", filepath) process.exit(1) } - sitemap = fs.readFileSync(filepath, {encoding: 'utf8'}) + sitemap = fs.readFileSync(filepath, { encoding: 'utf8' }) } const urls = sitemapUrls.extractUrls(sitemap) diff --git a/lib/index.js b/lib/index.js index e00c0e3..3ad1800 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,9 +3,9 @@ const cheerio = require('cheerio') function extractUrls(xml) { const urls = [] - const $ = cheerio.load(xml, {xmlMode: true}) + const $ = cheerio.load(xml, { xmlMode: true }) - $('loc').each(function () { + $('loc').each(function() { const url = $(this).text() if (urls.indexOf(url) < 0) { diff --git a/package.json b/package.json index 512ea90..ad800fd 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,7 @@ "version": "2.0.0", "description": "Extract URLs from an XML sitemap.", "author": "Roland Warmerdam (https://roland.codes)", - "keywords": [ - "sitemap", - "url", - "parse", - "extract" - ], + "keywords": ["sitemap", "url", "parse", "extract"], "repository": "Rowno/sitemap-urls", "license": "MIT", "main": "lib/index.js", @@ -28,31 +23,32 @@ "meow": "^4.0.0" }, "devDependencies": { + "eslint-config-prettier": "^2.9.0", "execa": "^0.8.0", "husky": "^0.14.3", "jest": "^21.2.1", "lint-staged": "^6.0.0", + "prettier": "^1.9.1", "xo": "^0.18.2" }, - "files": [ - "lib" - ], + "files": ["lib"], "xo": { "space": true, "semicolon": false, + "extends": ["prettier"], "overrides": [ { "files": "**/__tests__/**/*.js", - "envs": [ - "jest" - ] + "envs": ["jest"] } ] }, + "prettier": { + "semi": false, + "singleQuote": true + }, "lint-staged": { - "*.js": [ - "xo --fix", - "git add" - ] + "*.js": ["xo --fix", "prettier --write", "git add"], + "*.json": ["prettier --write", "git add"] } } diff --git a/yarn.lock b/yarn.lock index 5bbdc6c..a2766a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -988,6 +988,12 @@ escope@^3.6.0: esrecurse "^4.1.0" estraverse "^4.1.1" +eslint-config-prettier@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-2.9.0.tgz#5ecd65174d486c22dff389fe036febf502d468a3" + dependencies: + get-stdin "^5.0.1" + eslint-config-xo@^0.18.0: version "0.18.2" resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.18.2.tgz#0a157120875619929e735ffd6b185c41e8a187af" @@ -1407,7 +1413,7 @@ get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" -get-stdin@^5.0.0: +get-stdin@^5.0.0, get-stdin@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398" @@ -3062,6 +3068,10 @@ preserve@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" +prettier@^1.9.1: + version "1.9.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.1.tgz#41638a0d47c1efbd1b7d5a742aaa5548eab86d70" + pretty-format@^21.2.1: version "21.2.1" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.2.1.tgz#ae5407f3cf21066cd011aa1ba5fce7b6a2eddb36"