├── .gitignore ├── .travis.yml ├── README.md ├── config └── config.exs ├── lib └── fixme.ex ├── mix.exs ├── mix.lock └── test ├── fixme_test.exs └── test_helper.exs /.gitignore: -------------------------------------------------------------------------------- 1 | /_build 2 | /deps 3 | /doc 4 | erl_crash.dump 5 | *.ez 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: elixir 2 | 3 | elixir: 4 | - 1.10 5 | - 1.9 6 | - 1.8 7 | - 1.7 8 | - 1.6 9 | -otp_release: 21.0 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FIXME for Elixir 2 | 3 | [![Build Status](https://travis-ci.org/henrik/fixme-elixir.svg?branch=master)](https://travis-ci.org/henrik/fixme-elixir) 4 | [![Hex](https://img.shields.io/hexpm/v/fixme.svg)](https://hex.pm/packages/fixme) 5 | 6 | ## What is it? 7 | 8 | FIXME comments that raise during compilation after a certain point in time: 9 | 10 | ``` elixir 11 | defmodule MyCode do 12 | import FIXME 13 | 14 | def my_function do 15 | fixme 2020-12-01, "Stop hard-coding currency." 16 | currency = "USD" 17 | # … 18 | end 19 | end 20 | ``` 21 | 22 | Starting December 1st 2020, the `fixme` line in the example above would raise a compile-time exception with the message "Fix by 2020-12-01: Stop hard-coding currency." 23 | 24 | Optionally, you can also get warnings before that date, reminding you it's coming up. 25 | 26 | Because this happens at compile time, it will never raise or warn in production. 27 | 28 | You may want to use these bad boys next to: 29 | 30 | * Temporary quick fixes, to ensure they really are temporary. 31 | * Code that supports legacy workflows during a transitional period. 32 | * Experiments, to remember to evaluate them and make a decision. 33 | * Anything else you can't do now but should fix later. 34 | 35 | Pro-tip: make sure it's clear from the exception or from a separate comment just what should be done – sometimes not even the person who wrote the quick fix will remember what you're meant to change. 36 | 37 | 38 | ## Warnings before the due date 39 | 40 | You can opt into warnings before the due date arrives – but you'll still get exceptions on and after the date. 41 | 42 | The warnings look like: 43 | 44 | ``` text 45 | warning: Fix by 2020-12-01: Stop hard-coding currency. 46 | lib/my_code.ex:5 47 | ``` 48 | 49 | You can configure this either application-wide or per `fixme` call. 50 | 51 | If you want it application-wide, do this in your `config/config.exs`: 52 | 53 | 54 | ```elixir 55 | config :fixme, warn: true 56 | ``` 57 | 58 | To specify it per call: 59 | 60 | ```elixir 61 | fixme 2020-12-01, "Stop hard-coding currency.", warn: true 62 | ``` 63 | 64 | This overrides the application-wide setting. So if it's off application-wide (this is the default), you can selectively opt into warnings for some FIXME. If it's on application-wise, you can selectively opt out of some. 65 | 66 | 67 | ## Gotchas 68 | 69 | * If you see an error like "** (CompileError) lib/foo.ex:2: undefined function fixme/2", you probably forgot to `import FIXME`. You need to explicitly import it, because it's a macro. 70 | 71 | * A consequence of running at compile time is that if the date passes and the file is not recompiled, there will be no exception. You can either accept that (maybe untouched code can remain that way until the next time), or you can `mix compile --force`. 72 | 73 | 74 | ## Installation 75 | 76 | Add the dependency to your project's `mix.exs`: 77 | 78 | ``` elixir 79 | defp deps do 80 | [ 81 | {:fixme, "> 0.0.0"}, 82 | ] 83 | end 84 | ``` 85 | 86 | Then fetch it: 87 | 88 | ``` text 89 | mix deps.get 90 | ``` 91 | 92 | ## Tests 93 | 94 | If you're developing this library, you can run its tests with: 95 | 96 | ``` text 97 | mix test 98 | ``` 99 | 100 | CI runs the tests against multiple Elixir versions. See `.travis.yml`. The policy is to test against [every version that still receives security patches](https://hexdocs.pm/elixir/compatibility-and-deprecations.html). 101 | 102 | ## Also see 103 | 104 | * [Blocked](https://github.com/Qqwy/elixir-blocked), which triggers on GitHub issues rather than dates 105 | * My ["fixme" Ruby gem](https://github.com/henrik/fixme) 106 | 107 | 108 | ## License 109 | 110 | Copyright (c) 2015+ Henrik Nyh 111 | 112 | MIT License 113 | 114 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 115 | 116 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 117 | 118 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 119 | -------------------------------------------------------------------------------- /config/config.exs: -------------------------------------------------------------------------------- 1 | # This file is responsible for configuring your application 2 | # and its dependencies with the aid of the Mix.Config module. 3 | use Mix.Config 4 | 5 | # This configuration is loaded before any dependency and is restricted 6 | # to this project. If another project depends on this project, this 7 | # file won't be loaded nor affect the parent project. For this reason, 8 | # if you want to provide default values for your application for third- 9 | # party users, it should be done in your mix.exs file. 10 | 11 | # Sample configuration: 12 | # 13 | # config :logger, :console, 14 | # level: :info, 15 | # format: "$date $time [$level] $metadata$message\n", 16 | # metadata: [:user_id] 17 | 18 | # It is also possible to import configuration files, relative to this 19 | # directory. For example, you can emulate configuration per environment 20 | # by uncommenting the line below and defining dev.exs, test.exs and such. 21 | # Configuration from the imported file will override the ones defined 22 | # here (which is why it is important to import them last). 23 | # 24 | # import_config "#{Mix.env}.exs" 25 | -------------------------------------------------------------------------------- /lib/fixme.ex: -------------------------------------------------------------------------------- 1 | defmodule FIXME do 2 | defmacro fixme( 3 | {:-, _, [{:-, _, [year, month]}, day]}, 4 | message, 5 | opts \\ [] 6 | ) do 7 | {opts, _} = Code.eval_quoted(opts) 8 | 9 | # Injectable `today` for tests. 10 | current_date = opts[:today] || (:calendar.local_time |> elem(0)) 11 | 12 | warn? = 13 | case opts[:warn] do 14 | nil -> Application.get_env(:fixme, :warn, false) 15 | warn? -> warn? 16 | end 17 | 18 | fixme_date = {year, month, day} 19 | due? = current_date >= fixme_date 20 | 21 | message = "Fix by #{year}-#{zeropad(month)}-#{zeropad(day)}: #{message}" 22 | cond do 23 | due? -> raise message 24 | warn? -> 25 | %{file: file, line: line} = __CALLER__ 26 | IO.warn(message <> "\n #{file}:#{line}", []) 27 | true -> nil 28 | end 29 | end 30 | 31 | defp zeropad(number) do 32 | number |> Integer.to_string |> String.pad_leading(2, "0") 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /mix.exs: -------------------------------------------------------------------------------- 1 | defmodule FIXME.Mixfile do 2 | use Mix.Project 3 | 4 | def project do 5 | [ 6 | app: :fixme, 7 | version: "0.2.0", 8 | elixir: ">= 1.6.0", 9 | description: "FIXME comments that raise after a certain point in time.", 10 | package: package(), 11 | build_embedded: Mix.env == :prod, 12 | start_permanent: Mix.env == :prod, 13 | deps: deps(), 14 | 15 | # Docs 16 | name: "FIXME", 17 | source_url: "https://github.com/henrik/fixme-elixir", 18 | docs: [ 19 | main: "readme", 20 | extras: ["README.md"], 21 | ] 22 | ] 23 | end 24 | 25 | defp package do 26 | [ 27 | licenses: ["MIT"], 28 | maintainers: ["Henrik Nyh"], 29 | links: %{"GitHub" => "https://github.com/henrik/fixme-elixir"}, 30 | ] 31 | end 32 | 33 | # Configuration for the OTP application 34 | # 35 | # Type `mix help compile.app` for more information 36 | def application do 37 | [applications: [:logger]] 38 | end 39 | 40 | defp deps do 41 | [ 42 | {:ex_doc, "~> 0.21", only: :dev, runtime: false}, 43 | ] 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /mix.lock: -------------------------------------------------------------------------------- 1 | %{ 2 | "dogma": {:git, "git://github.com/henrik/dogma.git", "a72d912079f05a93f9705d659842ab7c1470662d", []}, 3 | "earmark": {:hex, :earmark, "1.4.5", "62ffd3bd7722fb7a7b1ecd2419ea0b458c356e7168c1f5d65caf09b4fbdd13c8", [:mix], [], "hexpm", "b7d0e6263d83dc27141a523467799a685965bf8b13b6743413f19a7079843f4f"}, 4 | "ex_doc": {:hex, :ex_doc, "0.22.1", "9bb6d51508778193a4ea90fa16eac47f8b67934f33f8271d5e1edec2dc0eee4c", [:mix], [{:earmark, "~> 1.4.0", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "d957de1b75cb9f78d3ee17820733dc4460114d8b1e11f7ee4fd6546e69b1db60"}, 5 | "makeup": {:hex, :makeup, "1.0.3", "e339e2f766d12e7260e6672dd4047405963c5ec99661abdc432e6ec67d29ef95", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "2e9b4996d11832947731f7608fed7ad2f9443011b3b479ae288011265cdd3dad"}, 6 | "makeup_elixir": {:hex, :makeup_elixir, "0.14.1", "4f0e96847c63c17841d42c08107405a005a2680eb9c7ccadfd757bd31dabccfb", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f2438b1a80eaec9ede832b5c41cd4f373b38fd7aa33e3b22d9db79e640cbde11"}, 7 | "nimble_parsec": {:hex, :nimble_parsec, "0.6.0", "32111b3bf39137144abd7ba1cce0914533b2d16ef35e8abc5ec8be6122944263", [:mix], [], "hexpm", "27eac315a94909d4dc68bc07a4a83e06c8379237c5ea528a9acff4ca1c873c52"}, 8 | "poison": {:hex, :poison, "1.5.0"}, 9 | } 10 | -------------------------------------------------------------------------------- /test/fixme_test.exs: -------------------------------------------------------------------------------- 1 | defmodule FIXMETest do 2 | use ExUnit.Case 3 | import CompileTimeAssertions 4 | import ExUnit.CaptureIO 5 | 6 | setup context do 7 | if context[:warnings_enabled] do 8 | Application.put_env(:fixme, :warn, true) 9 | on_exit fn -> Application.delete_env(:fixme, :warn) end 10 | end 11 | :ok 12 | end 13 | 14 | test "does not raise before date" do 15 | import FIXME 16 | fixme 9999-07-01, "look for jetpack" 17 | end 18 | 19 | test "raises after date" do 20 | assert_compile_time_raise RuntimeError, "Fix by 1983-07-26: be born", fn -> 21 | import FIXME 22 | fixme 1983-07-26, "be born" 23 | end 24 | end 25 | 26 | test "raises on date" do 27 | assert_compile_time_raise RuntimeError, "Fix by 9999-07-01: look for jetpack", fn -> 28 | import FIXME 29 | fixme 9999-07-01, "look for jetpack", today: {9999, 7, 1} 30 | end 31 | end 32 | 33 | test "warns during compile time before the date if passed `warn: true` during invokation, even if an application setting is not present" do 34 | warning = capture_io(:stderr, fn -> 35 | Code.eval_string """ 36 | import FIXME 37 | fixme 9999-07-01, "look for jetpack", warn: true 38 | """, [], file: "myfile.ex" 39 | end) 40 | assert warning =~ "Fix by 9999-07-01: look for jetpack\n myfile.ex:2" 41 | end 42 | 43 | @tag warnings_enabled: true 44 | test "warns during compile before the date if `warn: true` is set in application settings" do 45 | warning = capture_io(:stderr, fn -> 46 | Code.eval_string """ 47 | import FIXME 48 | fixme 9999-07-01, "look for jetpack" 49 | """, [], file: "myfile.ex" 50 | end) 51 | assert warning =~ "Fix by 9999-07-01: look for jetpack\n myfile.ex:2" 52 | end 53 | 54 | @tag warnings_enabled: true 55 | test "does not warn during compile before the date if `warn: true` in application setting, but passed `warn: false` in the macro call" do 56 | warning = capture_io(:stderr, fn -> 57 | Code.eval_string """ 58 | import FIXME 59 | fixme 9999-07-01, "look for jetpack", warn: false 60 | """, [], file: "myfile.ex" 61 | end) 62 | assert warning == "" 63 | end 64 | 65 | @tag warnings_enabled: true 66 | test "warns during compile before the date if `warn: true` both in application settings and in the macro call" do 67 | warning = capture_io(:stderr, fn -> 68 | Code.eval_string """ 69 | import FIXME 70 | fixme 9999-07-01, "look for jetpack", warn: true 71 | """, [], file: "myfile.ex" 72 | end) 73 | assert warning =~ "Fix by 9999-07-01: look for jetpack\n myfile.ex:2" 74 | end 75 | 76 | @tag warnings_enabled: true 77 | test "raises on date even if warn is true" do 78 | assert_compile_time_raise RuntimeError, "Fix by 9999-07-01: look for jetpack", fn -> 79 | import FIXME 80 | fixme 9999-07-01, "look for jetpack", today: {9999, 7, 1} 81 | end 82 | end 83 | 84 | @tag warnings_enabled: true 85 | test "raises after date even if warn is true" do 86 | assert_compile_time_raise RuntimeError, "Fix by 1983-07-26: be born", fn -> 87 | import FIXME 88 | fixme 1983-07-26, "be born" 89 | end 90 | end 91 | 92 | test "sanity" do 93 | # Let's be extra confident that we can compare dates as tuples. 94 | assert {2015, 1, 1} > {2014, 12, 31} 95 | assert {2015, 2, 1} > {2015, 1, 1} 96 | assert {2015, 1, 2} > {2015, 1, 1} 97 | assert {2015, 1, 1} == {2015, 1, 1} 98 | end 99 | end 100 | -------------------------------------------------------------------------------- /test/test_helper.exs: -------------------------------------------------------------------------------- 1 | ExUnit.start() 2 | 3 | defmodule CompileTimeAssertions do 4 | defmacro assert_compile_time_raise(expected_exception, expected_message, fun) do 5 | fun = Macro.escape(fun) 6 | 7 | quote do 8 | assert_raise unquote(expected_exception), unquote(expected_message), fn -> 9 | Code.eval_quoted(unquote(fun)) 10 | end 11 | end 12 | end 13 | end 14 | --------------------------------------------------------------------------------