From 93c3ef8a4286dc81e449e42f791909fb6e37d8c4 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 29 Nov 2024 17:54:09 +0100 Subject: [PATCH] Include files from a source-directory if that source-directory is in elm-stuff --- .gitignore | 1 + CHANGELOG.md | 1 + lib/elm-files.js | 6 ++-- .../elm-stuff/src/Util.elm | 6 ++++ test/project-with-files-in-elm-stuff/elm.json | 25 ++++++++++++++ .../review/elm.json | 33 +++++++++++++++++++ .../review/src/ReviewConfig.elm | 21 ++++++++++++ .../src/Folder/Unused.elm | 5 +++ .../src/Folder/Used.elm | 6 ++++ .../src/Main.elm | 6 ++++ .../src/UtilNotUsed.elm | 3 ++ test/review.test.js | 9 +++++ ...rc.elm-project-with-files-in-elm-stuff.txt | 29 ++++++++++++++++ 13 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 test/project-with-files-in-elm-stuff/elm-stuff/src/Util.elm create mode 100644 test/project-with-files-in-elm-stuff/elm.json create mode 100644 test/project-with-files-in-elm-stuff/review/elm.json create mode 100644 test/project-with-files-in-elm-stuff/review/src/ReviewConfig.elm create mode 100644 test/project-with-files-in-elm-stuff/src/Folder/Unused.elm create mode 100644 test/project-with-files-in-elm-stuff/src/Folder/Used.elm create mode 100644 test/project-with-files-in-elm-stuff/src/Main.elm create mode 100644 test/project-with-files-in-elm-stuff/src/UtilNotUsed.elm create mode 100644 test/snapshots/review/src.elm-project-with-files-in-elm-stuff.txt diff --git a/.gitignore b/.gitignore index dfe286826..b6cba3eb8 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ build/Release # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules elm-stuff +!test/project-with-files-in-elm-stuff/elm-stuff/src/Util.elm temporary build/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 539a3d89e..2d6169646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - The `--compiler` flag now additionally resolves the compiler path using the `PATH` environment variable (more easily enabling `elm-review --compiler lamdera` for instance). - The `--elm-format-path` flag now additionally resolves the path to `elm-format` using the `PATH` environment variable. - Fixed an issue where the initial rule created with `elm-review new-package` was always a module rule, even when it was requested to be a project rule. Thanks to [@mateusfpleite](https://github.com/mateusfpleite)! +- Fixed an issue where files in source-directories under `elm-stuff/` would not be included in the analysis. - Plenty of behind the scenes improvement to the maintenance of the repository. Thanks to [@lishaduck](https://github.com/lishaduck) for all of those. ## [2.12.0] - 2024-06-14 diff --git a/lib/elm-files.js b/lib/elm-files.js index d39112613..fc239c966 100644 --- a/lib/elm-files.js +++ b/lib/elm-files.js @@ -292,8 +292,6 @@ async function findFiles(isFromCliArguments, directory) { return await findFromFolder(directory, path_); } -const globIgnore = ['**/elm-stuff/**']; - /** * Find Elm files in directory * @@ -309,7 +307,7 @@ async function findForCliArguments(directory, path_) { return { files: await glob(path_, { nocase: true, - ignore: globIgnore, + ignore: [`${path_}/**/elm-stuff/**`], nodir: true }), directory @@ -343,7 +341,7 @@ async function findFromFolder(directory, path_) { return { files: await glob(`${path_}/**/*.elm`, { nocase: true, - ignore: globIgnore, + ignore: [`${path_}/**/elm-stuff/**`], nodir: false }), directory diff --git a/test/project-with-files-in-elm-stuff/elm-stuff/src/Util.elm b/test/project-with-files-in-elm-stuff/elm-stuff/src/Util.elm new file mode 100644 index 000000000..158d98fce --- /dev/null +++ b/test/project-with-files-in-elm-stuff/elm-stuff/src/Util.elm @@ -0,0 +1,6 @@ +module Util exposing (test) + +test : a -> a +test x = x + +unused = 1 \ No newline at end of file diff --git a/test/project-with-files-in-elm-stuff/elm.json b/test/project-with-files-in-elm-stuff/elm.json new file mode 100644 index 000000000..add4d6974 --- /dev/null +++ b/test/project-with-files-in-elm-stuff/elm.json @@ -0,0 +1,25 @@ +{ + "type": "application", + "source-directories": [ + "src", + "elm-stuff/src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0" + }, + "indirect": { + "elm/json": "1.1.3", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/test/project-with-files-in-elm-stuff/review/elm.json b/test/project-with-files-in-elm-stuff/review/elm.json new file mode 100644 index 000000000..0ef9ef7fe --- /dev/null +++ b/test/project-with-files-in-elm-stuff/review/elm.json @@ -0,0 +1,33 @@ +{ + "type": "application", + "source-directories": [ + "src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "elm/core": "1.0.5", + "elm/json": "1.1.3", + "elm/project-metadata-utils": "1.0.2", + "jfmengels/elm-review": "2.14.1", + "jfmengels/elm-review-unused": "1.2.3", + "stil4m/elm-syntax": "7.3.7" + }, + "indirect": { + "elm/bytes": "1.0.8", + "elm/html": "1.0.0", + "elm/parser": "1.1.0", + "elm/random": "1.0.0", + "elm/regex": "1.0.0", + "elm/time": "1.0.0", + "elm/virtual-dom": "1.0.3", + "elm-explorations/test": "2.2.0", + "rtfeldman/elm-hex": "1.0.0", + "stil4m/structured-writer": "1.0.3" + } + }, + "test-dependencies": { + "direct": {}, + "indirect": {} + } +} diff --git a/test/project-with-files-in-elm-stuff/review/src/ReviewConfig.elm b/test/project-with-files-in-elm-stuff/review/src/ReviewConfig.elm new file mode 100644 index 000000000..254cf9258 --- /dev/null +++ b/test/project-with-files-in-elm-stuff/review/src/ReviewConfig.elm @@ -0,0 +1,21 @@ +module ReviewConfig exposing (config) + +{-| Do not rename the ReviewConfig module or the config function, because +`elm-review` will look for these. + +To add packages that contain rules, add them to this review project using + + `elm install author/packagename` + +when inside the directory containing this file. + +-} + +import NoUnused.Variables +import Review.Rule exposing (Rule) + + +config : List Rule +config = + [ NoUnused.Variables.rule + ] diff --git a/test/project-with-files-in-elm-stuff/src/Folder/Unused.elm b/test/project-with-files-in-elm-stuff/src/Folder/Unused.elm new file mode 100644 index 000000000..76635ddb5 --- /dev/null +++ b/test/project-with-files-in-elm-stuff/src/Folder/Unused.elm @@ -0,0 +1,5 @@ +module Folder.Unused exposing (..) + + +a = + 1 diff --git a/test/project-with-files-in-elm-stuff/src/Folder/Used.elm b/test/project-with-files-in-elm-stuff/src/Folder/Used.elm new file mode 100644 index 000000000..eceabf295 --- /dev/null +++ b/test/project-with-files-in-elm-stuff/src/Folder/Used.elm @@ -0,0 +1,6 @@ +module Folder.Used exposing (one) + + +one : Int +one = + 1 diff --git a/test/project-with-files-in-elm-stuff/src/Main.elm b/test/project-with-files-in-elm-stuff/src/Main.elm new file mode 100644 index 000000000..f8682e605 --- /dev/null +++ b/test/project-with-files-in-elm-stuff/src/Main.elm @@ -0,0 +1,6 @@ +module Main exposing (..) + +import Util as List +import UtilNotUsed as List + +useImportAliasFromElmstuff x = List.test x \ No newline at end of file diff --git a/test/project-with-files-in-elm-stuff/src/UtilNotUsed.elm b/test/project-with-files-in-elm-stuff/src/UtilNotUsed.elm new file mode 100644 index 000000000..c27c0aac9 --- /dev/null +++ b/test/project-with-files-in-elm-stuff/src/UtilNotUsed.elm @@ -0,0 +1,3 @@ +module UtilNotUsed exposing (x) + +x = 1 \ No newline at end of file diff --git a/test/review.test.js b/test/review.test.js index 260ebd669..c95d2e74b 100644 --- a/test/review.test.js +++ b/test/review.test.js @@ -135,3 +135,12 @@ test('Running on project with a directory ending in .elm (with arg)', async () = ); expect(output).toMatchFile(testName('src.elm-project-with-arg')); }); + +test('Includes files from a source-directory if that source-directory is in elm-stuff', async () => { + const output = await TestCli.runAndExpectError('', { + project: 'project-with-files-in-elm-stuff' + }); + expect(output).toMatchFile( + testName('src.elm-project-with-files-in-elm-stuff') + ); +}); diff --git a/test/snapshots/review/src.elm-project-with-files-in-elm-stuff.txt b/test/snapshots/review/src.elm-project-with-files-in-elm-stuff.txt new file mode 100644 index 000000000..e6369d22e --- /dev/null +++ b/test/snapshots/review/src.elm-project-with-files-in-elm-stuff.txt @@ -0,0 +1,29 @@ +-- ELM-REVIEW ERROR --------------------------------- elm-stuff/src/Util.elm:6:1 + +(fix) NoUnused.Variables: Top-level variable `unused` is not used + +6| unused = 1 + ^^^^^^ + +You should either use this value somewhere, or remove it at the location I +pointed at. + +elm-stuff/src/Util.elm ↑ +====o======================================================================o==== +↓ src/Main.elm + + +-- ELM-REVIEW ERROR ------------------------------------------ src/Main.elm:4:23 + +(fix) NoUnused.Variables: Module alias `List` is not used + +3| import Util as List +4| import UtilNotUsed as List + ^^^^ + +You should either use this value somewhere, or remove it at the location I +pointed at. + +Errors marked with (fix) can be fixed automatically using `elm-review --fix`. + +I found 2 errors in 2 files.