Skip to content

Commit

Permalink
Merge branch 'GH-29' into main
Browse files Browse the repository at this point in the history
* GH-29:
  GH-29: Sanitised root path to fix gitignore parsing.
  GH-29: Reverted improper use of path.resolve.
  GH-29: Use path.resolve instead of manually concatenating path.
  GH-29: Tweaked gitignore parsing.
  GH-29: Improved positivity check.
  GH-29: Added (JS)docs for new includes/excludes merging.
  GH-29: Improved code coverage of stylelint tests to avoid breaking CI builds.
  GH-29: Updated .gitignore tests to work with recent changes.
  GH-29: Made sources use 'nomerge' and improved affected tests.
  GH-29: Implement alternate merge strategy for includes/excludes.
  GH-31: Add tests for lintspaces.newlines and additional default excludes.
  • Loading branch information
amb26 committed Apr 20, 2021
2 parents 468e89c + 93dbc38 commit c674a96
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 97 deletions.
14 changes: 1 addition & 13 deletions .fluidlintallrc-gitignore-disabled.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,7 @@
},
"lintspaces": {
"newlines": {
"enabled": true,
"includes": [
"./css/*",
"./images/*",
"./js/*",
"./json/*",
"./json5/*",
"./md/*",
"./node_modules/*",
"./other/*",
"./scss/*",
"./*"
]
"includes": ["./md/**/*.md"]
}
}
}
38 changes: 19 additions & 19 deletions .fluidlintallrc-gitignore.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"rootPath": "@expand:fluid.module.resolvePath(%fluid-lint-all/tests/fixtures)",
"sources": {
"css": ["./css/**/*.css"],
"js": ["./js/**/*.js"],
"json": ["./json/**/*.json"],
"json5": ["./json5/**/*.json5"],
"md": ["./md/**/*.md"],
"scss": ["./scss/**/*.scss"]
"css": [
"./css/**/*.css"
],
"js": [
"./js/**/*.js"
],
"json": [
"./json/**/*.json"
],
"json5": [
"./json5/**/*.json5"
],
"md": [
"./md/**/*.md"
],
"scss": [
"./scss/**/*.scss"
]
},
"lintspaces": {
"newlines": {
"enabled": true,
"includes": [
"./css/*",
"./images/*",
"./js/*",
"./json/*",
"./json5/*",
"./md/*",
"./node_modules/*",
"./other/*",
"./scss/*",
"./*"
]
"includes": ["./md/**/*.md"]
}
}
}
42 changes: 42 additions & 0 deletions .fluidlintallrc-invalid-stylelint-option.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"eslint": {
"js": {
"enabled": false
},
"json": {
"enabled": false
},
"md": {
"enabled": false
}
},
"json5lint": {
"enabled": false
},
"jsonlint": {
"enabled": false
},
"lintspaces": {
"jsonindentation": {
"enabled": false
},
"newlines": {
"enabled": false
}
},
"markdownlint": {
"enabled": false
},
"mdjsonlint": {
"enabled": false
},
"stylelint": {
"options": {
"config": {
"rules": {
"string-no-newline": "bad value"
}
}
}
}
}
39 changes: 39 additions & 0 deletions .fluidlintallrc-no-excludes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"sources": {
"json5": ["./src/**/*.json5", "./tests/**/*.json5", "./*.json5", "./tests/**/*.with.extensions"]
},
"eslint": {
"js": {
"excludes": "@expand:fluid.generate(64,'')"
},
"json": {
"excludes": "@expand:fluid.generate(64,'')"
},
"md": {
"excludes": "@expand:fluid.generate(64,'')"
}
},
"json5lint": {
"excludes": "@expand:fluid.generate(64,'')"
},
"jsonlint": {
"excludes": "@expand:fluid.generate(64,'')"
},
"lintspaces": {
"jsonindentation": {
"excludes": "@expand:fluid.generate(64,'')"
},
"newlines": {
"excludes": "@expand:fluid.generate(64,'')"
}
},
"markdownlint": {
"excludes": "@expand:fluid.generate(64,'')"
},
"mdjsonlint": {
"excludes": "@expand:fluid.generate(64,'')"
},
"stylelint": {
"excludes": "@expand:fluid.generate(64,'')"
}
}
2 changes: 1 addition & 1 deletion .fluidlintallrc-nofiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"lintspaces": {
"newlines": {
"includes": ["./foo/**/*", "./bar/**/*", "./baz/**/*", "./qux/**/*"]
"includes": ["!./src/**/*", "!./tests/**/*", "!./*"]
}
}
}
24 changes: 21 additions & 3 deletions .fluidlintallrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,31 @@
"excludes": [
"tests/fixtures/css/bad.css",
"tests/fixtures/scss/bad.scss",
"tests/fixtures/md/badJson5.md",
"tests/fixtures/images/*"
"tests/fixtures/md/bad*.md",
"tests/fixtures/images/*",
"*.aiff",
"*.eot",
"*.gif",
"*.jpg",
"*.jpeg",
"*.mp3",
"*.mp4",
"*.otf",
"*.pdf",
"*.png",
"*.ppt",
"*.pptx",
"*.svg",
"*.wav",
"*.webm",
"*.webp",
"*.woff",
"*.woff2"
]
}
},
"markdownlint": {
"excludes": ["tests/fixtures/md/bad.md", "tests/fixtures/md/badJson5.md"]
"excludes": ["tests/fixtures/md/bad*.md"]
},
"mdjsonlint": {
"excludes": ["tests/fixtures/md/bad.md", "tests/fixtures/md/badJson5.md"]
Expand Down
34 changes: 31 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,42 @@ otherwise report any files that lack a trailing space as an error.
},
"lintspaces": {
"newlines": {
"excludes": ["./node_modules/**/*", "./src/assets/images/**/*"]
"excludes": ["./src/assets/images/**/*"]
}
}
}
```

Note that excludes replace rather than adding to the defaults, so (as shown above) you do have to add the (otherwise
default) exclude for content in the `node_modules` directory.
## Adding (or Disabling) Default Includes and Excludes

There are global includes and excludes defined by default. See [this file](./src/js/lint-all.js) for the default
configuration options.

This section describes adding your own includes and excludes, and disabling defaults. The following example adds a
single exclude to the defaults for the `lintspaces.newlines` check:

```json
{
"lintspaces": {
"newlines": {
"excludes": ["./src/assets/images/**/*"]
}
}
}
```

To disable an existing default pattern, pass a negated version of the same pattern. For example, checking of trailing
newlines is currently disabled for SVG files. If you want to check SVG files, you would use a configuration like:

```json
{
"lintspaces": {
"newlines": {
"excludes": ["!*.svg"]
}
}
}
```

## Migrating from `fluid-grunt-lint-all`

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"infusion": "3.0.0-dev.20201113T153152Z.32176dcbe.FLUID-6145",
"json5": "2.1.3",
"jsonlint": "1.6.3",
"lintspaces": "0.7.0",
"lintspaces": "0.8.1",
"markdownlint": "0.22.0",
"markdownlint-config-fluid": "0.1.2",
"minimatch": "3.0.4",
Expand Down
9 changes: 6 additions & 3 deletions src/js/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,23 @@ fluid.lintAll.runChecks = function (that, checksToRun) {
// Use fluid-glob to get the list of files.
var filesToScan = fluid.glob.findFiles(that.options.rootPath, that.options.config.includes, that.options.config.excludes, that.options.minimatchOptions);


if (that.options.useGitIgnore) {
var gitignorePath = path.resolve(that.options.rootPath, ".gitignore");
if (fs.existsSync(gitignorePath)) {
var rawGitIgnoreContents = fs.readFileSync(gitignorePath, { encoding: "utf8" });
var gitIgnores = rawGitIgnoreContents.split("\n").filter(function (singleEntry) {
var gitIgnores = rawGitIgnoreContents.split(/\r?\n/).filter(function (singleEntry) {
var trimmedEntry = singleEntry.trim();
if (trimmedEntry === "" || trimmedEntry.startsWith("#")) { return false; }
return true;
});

// As we are comparing patterns to patterns, we need to ensure that windows-style paths are converted
// and stripped of their drive letters.
var sanitisedRootPath = fluid.glob.sanitisePath(that.options.rootPath);
var filesToIgnore = [];
fluid.each(gitIgnores, function (singleGitIgnore) {
var pathedPattern = that.options.rootPath + "/" + singleGitIgnore;
// We cannot use path.resolve here because our glob patterns are all expressed with forward slashes.
var pathedPattern = sanitisedRootPath + "/" + singleGitIgnore;
var filesToIgnoreForThisPattern = minimatch.match(filesToScan, pathedPattern, that.options.minimatchOptions);
if (filesToIgnoreForThisPattern.length) {
filesToIgnore = filesToIgnore.concat(filesToIgnoreForThisPattern);
Expand Down
Loading

0 comments on commit c674a96

Please sign in to comment.