From 71aab51c854da511ab3665d7b2739b40207b0bf8 Mon Sep 17 00:00:00 2001 From: Josh Adams Date: Fri, 13 Oct 2017 18:40:32 -0600 Subject: [PATCH 1/2] Add coala configuration and test.sh - Use coala.io to test that data/projects.json matches the 2-space style and is valid json. --- .coafile | 7 +++++++ .gitignore | 2 ++ data/projects.json | 39 +++++++++++++++++++++++++-------------- test.sh | 4 ++++ 4 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 .coafile create mode 100755 test.sh diff --git a/.coafile b/.coafile new file mode 100644 index 0000000..fdf420b --- /dev/null +++ b/.coafile @@ -0,0 +1,7 @@ +[all] +ignore = .git/ + +[all.json] +bears = JSONFormatBear +files = data/projects.json +indent_size = 2 diff --git a/.gitignore b/.gitignore index c438999..5f806b6 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ build/ elm.js assets/styles.css npm-debug.log + +data/projects.json.orig diff --git a/data/projects.json b/data/projects.json index e870df6..4b3894e 100644 --- a/data/projects.json +++ b/data/projects.json @@ -6,7 +6,7 @@ "repositoryUrl": "https://github.com/rkrupinski/yt-repeater", "description": "YouTube repeater built with Elm." }, - { + { "name": "Graft3D", "previewImageUrl": "data/images/graft3d.png", "primaryUrl": "https://jesseilev.github.io/graft3d", @@ -20,43 +20,50 @@ "repositoryUrl": null, "description": "The instantaneous pace calculator for runners." }, - { "name": "Sandwich Delivery Game", + { + "name": "Sandwich Delivery Game", "previewImageUrl": "data/images/sandwich-delivery-game.png", "primaryUrl": "https://sandwich-delivery-game-webapp.s3.eu-central-1.amazonaws.com/index.html", "repositoryUrl": "https://github.com/innoq/sandwich-delivery-game", "description": "A Sandwich Delivery Game. A blog post describing the development of the game can be found in the github repo." }, - { "name": "Facebook Browser", + { + "name": "Facebook Browser", "previewImageUrl": "data/images/facebook-browser.png", "primaryUrl": "https://specious.github.io/facebook-browser", "repositoryUrl": "https://github.com/specious/facebook-browser", "description": "Search Facebook pages by name." }, - { "name": "Asteroids", + { + "name": "Asteroids", "previewImageUrl": "data/images/asteroids2.png", "primaryUrl": "https://justinmimbs.github.io/asteroids/", "repositoryUrl": "https://github.com/justinmimbs/asteroids", "description": "A game based on Asteroids Deluxe by Atari." }, - { "name": "Alertmanager", + { + "name": "Alertmanager", "previewImageUrl": "data/images/alertmanager.png", "primaryUrl": "https://prometheus.io/docs/alerting/alertmanager/", "repositoryUrl": "https://github.com/prometheus/alertmanager", "description": "Deduplicates, groups and routes alerts send by monitoring systems like Prometheus to services like PagerDuty, OpsGenie or plain e-mail." }, - { "name": "carna.io", + { + "name": "carna.io", "previewImageUrl": "data/images/carna-io.png", "primaryUrl": "https://www.carna.io", "repositoryUrl": "https://github.com/scepticulous/carna-ng", "description": "Body index and body fat percentage calculator in Elm." }, - { "name": "elm-hangman", + { + "name": "elm-hangman", "previewImageUrl": "data/images/elm-hangman.png", "primaryUrl": "http://puemos.github.io/elm-hangman/", "repositoryUrl": "https://github.com/puemos/elm-hangman/", "description": "The game of Hangman written in Elm." }, - { "name": "G.O.A.T.", + { + "name": "G.O.A.T.", "previewImageUrl": "data/images/goat.png", "primaryUrl": "http://gregziegan.com/goat/", "repositoryUrl": "https://github.com/thebritican/goat", @@ -258,7 +265,8 @@ "repositoryUrl": "https://github.com/astynax/elm-hekoish-watch", "description": "A simple cryptic fullscreen watch inspired by Tokyoflash \"Heko\" wristwatch" }, - { "name": "Elm Christmas tree", + { + "name": "Elm Christmas tree", "previewImageUrl": "data/images/elm-xmas-tree.png", "primaryUrl": "https://astynax.github.io/elm-xmas-tree", "repositoryUrl": "https://github.com/astynax/elm-xmas-tree", @@ -271,13 +279,15 @@ "repositoryUrl": "https://github.com/3tty0n/elm-online-markdown-editor", "description": "An online markdown editor written in Elm." }, - { "name": "MovieInfo", + { + "name": "MovieInfo", "previewImageUrl": "data/images/MovieInfo.jpg", "primaryUrl": "https://ciavash.gitlab.io/MovieInfo/", "repositoryUrl": "https://gitlab.com/CIAvash/MovieInfo", "description": "Information and ratings for Movies, TV Series and games" }, - { "name": "Orbiter 13", + { + "name": "Orbiter 13", "previewImageUrl": "http://i.imgur.com/6aKzubg.png", "primaryUrl": "http://www.chadtech.us/orbiter-13/", "repositoryUrl": "https://github.com/Chadtech/Orbiter-d", @@ -312,7 +322,7 @@ "description": "Playing with electronic circuits." }, { - "name":"Tabata Timer", + "name": "Tabata Timer", "previewImageUrl": "data/images/tabata-timer.png", "primaryUrl": "https://github.com/jackysee/tabata-timer", "repositoryUrl": "https://github.com/jackysee/tabata-timer", @@ -464,7 +474,8 @@ "primaryUrl": "http://niksilver.github.io/elm-tag-bubbles/", "repositoryUrl": "https://github.com/niksilver/elm-tag-bubbles", "description": "Exploring relationships between topics written about at theguardian.com" - }, { + }, + { "name": "Elm Goban", "previewImageUrl": "data/images/elm-goban.png", "primaryUrl": "http://mclauia.github.io/elm-goban/", @@ -658,7 +669,7 @@ "previewImageUrl": "data/images/elm-street-404.jpg", "primaryUrl": "http://zalando.github.io/elm-street-404/", "repositoryUrl": "https://github.com/zalando/elm-street-404", - "description": "404 Elm Street — a game where you have to deliver all the fashion to all the customers." + "description": "404 Elm Street \u2014 a game where you have to deliver all the fashion to all the customers." }, { "name": "elm-2048", diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..4ebfd07 --- /dev/null +++ b/test.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +# Run our linters +coala From 09aedf89e7903452ad2b20a6f788978db1778b24 Mon Sep 17 00:00:00 2001 From: Josh Adams Date: Fri, 13 Oct 2017 20:09:25 -0600 Subject: [PATCH 2/2] Add bear to check for duplicate project names --- .coafile | 9 +++++- .gitignore | 1 + bears/DuplicateProjectNamesBear.py | 51 ++++++++++++++++++++++++++++++ bears/ImageSizeBear.py | 17 ++++++++++ data/projects.json | 12 +++---- 5 files changed, 83 insertions(+), 7 deletions(-) create mode 100644 bears/DuplicateProjectNamesBear.py create mode 100644 bears/ImageSizeBear.py diff --git a/.coafile b/.coafile index fdf420b..8fbdea9 100644 --- a/.coafile +++ b/.coafile @@ -1,7 +1,14 @@ [all] ignore = .git/ +bear_dirs = bears [all.json] -bears = JSONFormatBear +bears = JSONFormatBear,DuplicateProjectNamesBear files = data/projects.json indent_size = 2 + +# [all.png] +# bears = ImageSizeBear +# files = README.md +# width = 1000 +# height = 800 diff --git a/.gitignore b/.gitignore index 5f806b6..0f85a08 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ assets/styles.css npm-debug.log data/projects.json.orig +bears/__pycache__ diff --git a/bears/DuplicateProjectNamesBear.py b/bears/DuplicateProjectNamesBear.py new file mode 100644 index 0000000..06aa540 --- /dev/null +++ b/bears/DuplicateProjectNamesBear.py @@ -0,0 +1,51 @@ +from coalib.bears.LocalBear import LocalBear +import json +import collections +from collections import OrderedDict +from coalib.results.Result import Result + + +class DuplicateProjectNamesBear(LocalBear): + + LANGUAGES = {'JSON'} + AUTHORS = {'DailyDrip'} + AUTHORS_EMAILS = {'devs@dailydrip.com'} + LICENSE = 'AGPL-3.0' + + def run(self, + filename, + file): + # Output a meaningful message if empty file given as input + if len(file) == 0: + yield Result.from_values(self, + 'This file is empty.', + file=filename) + return + + try: + json_content = json.loads(''.join(file), + object_pairs_hook=OrderedDict) + except JSONDecodeError as err: + err_content = match(r'(.*): line (\d+) column (\d+)', str(err)) + yield Result.from_values( + self, + 'This file does not contain parsable JSON. ' + + err_content.group(1) + '.', + file=filename, + line=int(err_content.group(2)), + column=int(err_content.group(3))) + return + + project_names = list(map(lambda entry: entry['name'], json_content)) + duplicates = [item for item, count in collections.Counter(project_names).items() if count > 1] + print(duplicates) + + if len(duplicates) > 0: + yield Result.from_values( + self, + 'The following project names are duplicated: ' + + ', '.join(duplicates), + file=filename + ) + + return diff --git a/bears/ImageSizeBear.py b/bears/ImageSizeBear.py new file mode 100644 index 0000000..687f500 --- /dev/null +++ b/bears/ImageSizeBear.py @@ -0,0 +1,17 @@ +from coalib.bearlib.abstractions.Linter import linter +from coalib.results.Result import Result + +@linter(executable='identify') +class ImageSizeBear: + USE_RAW_FILES = True + + def process_output(self, output, filename, file, + width: int, height: int): + return true + + @staticmethod + def create_arguments(filename, file, config_file): + """ + Bear configuration arguments. + """ + return (filename) diff --git a/data/projects.json b/data/projects.json index 4b3894e..a80ed9a 100644 --- a/data/projects.json +++ b/data/projects.json @@ -35,7 +35,7 @@ "description": "Search Facebook pages by name." }, { - "name": "Asteroids", + "name": "Asteroids (justinmimbs)", "previewImageUrl": "data/images/asteroids2.png", "primaryUrl": "https://justinmimbs.github.io/asteroids/", "repositoryUrl": "https://github.com/justinmimbs/asteroids", @@ -112,7 +112,7 @@ "description": "A Tic Tac Toe implementation with minimax built in. For freeCodeCamp." }, { - "name": "Elm Snake", + "name": "Elm Snake (nwjlyons)", "previewImageUrl": "data/images/nwjlyons-elm-snake.png", "primaryUrl": "http://snake.neillyons.io", "repositoryUrl": "https://github.com/nwjlyons/snake", @@ -140,7 +140,7 @@ "description": "A guide to harmful and poisonous plants in Nova Scotia, developed with content from the botany curator of the Nova Scotia Museum and input from the IWK Regional Poison Centre" }, { - "name": "Elm Snake", + "name": "Elm Snake (rkrupinski)", "previewImageUrl": "data/images/elm-snake.png", "primaryUrl": "https://rkrupinski.github.io/elm-snake/", "repositoryUrl": "https://github.com/rkrupinski/elm-snake", @@ -308,7 +308,7 @@ "description": "A simple TicTacToe game." }, { - "name": "Minesweeper", + "name": "Minesweeper (julianjelfs)", "previewImageUrl": "data/images/minesweeper.png", "primaryUrl": "https://julianjelfs.github.io/elm-minesweeper/dist/index.html", "repositoryUrl": "https://github.com/julianjelfs/elm-minesweeper", @@ -462,7 +462,7 @@ "description": "A little sound toy" }, { - "name": "Asteroids", + "name": "Asteroids (irh)", "previewImageUrl": "data/images/asteroids.png", "primaryUrl": "http://irh.github.io/asteroids", "repositoryUrl": "https://github.com/irh/asteroids", @@ -707,7 +707,7 @@ "description": "An SVG editor that combines programmatic and direct manipulation." }, { - "name": "Minesweeper", + "name": "Minesweeper (SekibOmazic)", "previewImageUrl": "data/images/elm-minesweeper.png", "primaryUrl": "http://sekibomazic.github.io/minesweeper", "repositoryUrl": "https://github.com/SekibOmazic/minesweeper",