Skip to content

Commit

Permalink
refactor: lint with statix
Browse files Browse the repository at this point in the history
  • Loading branch information
blaggacao committed Oct 17, 2022
1 parent 5cb1c6c commit 61df29f
Show file tree
Hide file tree
Showing 42 changed files with 114 additions and 112 deletions.
6 changes: 3 additions & 3 deletions docs/library-generated.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ asciidocToHtml "Hello `asciidoc`!"

:sectnums!:

[[lib.data.groupBy]]
=== groupBy
[[lib.data.groupByFlatten]]
=== groupByFlatten

==== Description

Expand Down Expand Up @@ -238,7 +238,7 @@ A property list of grouped attribute sets
[source, nix]
.Code
----
groupBy [
groupByFlatten [
{ type = "fruit"; name = "apple"; }
{ type = "fruit"; name = "pear"; }
{ type = "vegetable"; name = "lettuce"; }
Expand Down
4 changes: 4 additions & 0 deletions src/_automation/devshells.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ in
category = "dev";
package = nixpkgs.asciidoctor;
}
{
category = "dev";
package = nixpkgs.statix;
}
];
imports = [];
};
Expand Down
7 changes: 3 additions & 4 deletions src/_automation/libtests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ let
root = styxlib.conf.parseDecls {
inherit decls;
optionFn = o:
if o ? default
then o.default
else null;
o.default or null;
};

secondStageStyxlib = styxlib.hydrate (_: _: {config = root;});
Expand Down Expand Up @@ -125,7 +123,8 @@ in rec {
then extract
else {})
functions;
in (l.filter (x: x != {}) (l.flatten ex) ++ customTests);
in
l.filter (x: x != {}) (l.flatten ex) ++ customTests;

missingTests = let
missing = l.mapAttrsToList (name: fn: let
Expand Down
10 changes: 9 additions & 1 deletion src/_automation/tasks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ in {
'';
in
nixpkgs.writeScriptBin "run-tests" ''
echo ""
echo "------------------------------------------------"
echo ""
echo "\e[1;93mCode Linting:\e[0m"
echo ""
${l.getExe nixpkgs.statix} check
echo ""
echo "------------------------------------------------"
echo ""
Expand Down Expand Up @@ -63,7 +71,7 @@ in {
echo "Finished"
'';
update-doc = let
site = {...}: rec {
site = _: rec {
loaded =
(import inputs.self {
pkgs = nixpkgs;
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/agency/example/site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
title = "Home";
path = "/index.html";
template = templates.block-page.full;
layout = templates.layout;
inherit (templates) layout;
blocks = let
darken = d: d // {class = "bg-light-gray";};
in
Expand All @@ -118,7 +118,7 @@
# converting pages attribute set to a list
pageList = lib.generation.pagesToList {
inherit pages;
default = {layout = templates.layout;};
default = {inherit (templates) layout;};
};

site = lib.generation.mkSite {inherit files pageList;};
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/agency/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ with lib.lib; {
name = "Agency";
id = "agency";
license = licenses.asl20;
demoPage = https://styx-static.github.io/styx-theme-agency;
homepage = https://github.com/styx-static/styx-theme-agency;
demoPage = "https://styx-static.github.io/styx-theme-agency";
homepage = "https://github.com/styx-static/styx-theme-agency";
screenshot = ./screen.png;
documentation = readFile ./documentation.adoc;
description = ''
Expand Down
6 changes: 3 additions & 3 deletions src/data/styxthemes/generic-templates/example/site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

pages = rec {
basic = {
layout = templates.layout;
inherit (templates) layout;
template = templates.examples.basic;
path = "/basic.html";
# example of adding extra css / js to a page
Expand All @@ -71,15 +71,15 @@
};

starter = {
layout = templates.layout;
inherit (templates) layout;
template = templates.examples.starter;
path = "/starter.html";
title = "Starter Template for Bootstrap";
navbarTitle = "Starter";
};

theme = {
layout = templates.layout;
inherit (templates) layout;
template = templates.examples.theme;
path = "/index.html";
title = "Theme Template for Bootstrap";
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/generic-templates/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ with lib.lib; {
name = "Generic templates";
license = licenses.mit;
maintainers = with maintainers; [ericsagnes];
demoPage = https://styx-static.github.io/styx-theme-generic-templates;
homepage = https://github.com/styx-static/styx-theme-generic-templates;
demoPage = "https://styx-static.github.io/styx-theme-generic-templates";
homepage = "https://github.com/styx-static/styx-theme-generic-templates";
tags = ["generic-templates"];
screenshot = ./screen.png;
documentation = readFile ./documentation.adoc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.bootstrap;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
(templates.tag.link-css {href = "//maxcdn.bootstrapcdn.com/bootstrap/${cnf.version}/css/bootstrap.min.css";});
in
env.lib.template.documentedTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.font-awesome;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
(templates.tag.link-css {href = "//maxcdn.bootstrapcdn.com/font-awesome/${cnf.version}/css/font-awesome.min.css";});
in
env.lib.template.documentedTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.highlightjs;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
(templates.tag.link-css {href = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/${cnf.version}/styles/${cnf.style}.min.css";});
in
env.lib.template.documentedTemplate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.bootstrap;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
(templates.tag.script {
src = "//maxcdn.bootstrapcdn.com/bootstrap/${cnf.version}/js/bootstrap.min.js";
crossorigin = "anonymous";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.highlightjs;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
((templates.tag.script {
src = "//cdnjs.cloudflare.com/ajax/libs/highlight.js/${cnf.version}/highlight.min.js";
crossorigin = "anonymous";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.jquery;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
(templates.tag.script {
src = "//code.jquery.com/jquery-${cnf.version}.min.js";
crossorigin = "anonymous";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ env: let
with lib.lib; let
cnf = conf.theme.lib.mathjax;
in
optionalString (cnf.enable == true)
optionalString cnf.enable
(templates.tag.script {
src = "//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML";
crossorigin = "anonymous";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
env: let
template = {templates, ...}: args: templates.partials.head.meta args;
template = {templates, ...}: templates.partials.head.meta;
in
env.lib.template.documentedTemplate {
description = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ env: let
}: args:
with lib.lib; let
lang =
if html ? lang
then html.lang
else if hasAttrByPath ["html" "lang"] conf.theme
then conf.theme.html.lang
else "en";
html.lang
or (
if hasAttrByPath ["html" "lang"] conf.theme
then conf.theme.html.lang
else "en"
);
in '' <html ${lib.template.htmlAttr "lang" lang}>
${
(templates.partials.head.default args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ env: let
}: page:
with lib.lib; let
id =
if page ? disqusID
then page.disqusID
else if page ? rootPage
then page.rootPage.path
else page.path;
page.disqusID
or (
if page ? rootPage
then page.rootPage.path
else page.path
);
cnf = conf.theme.services.disqus;
in
optionalString (cnf.shortname != null)
Expand Down
6 changes: 3 additions & 3 deletions src/data/styxthemes/ghostwriter/example/site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
index = mkSplit {
title = "Home";
basePath = "/index";
itemsPerPage = conf.theme.itemsPerPage;
inherit (conf.theme) itemsPerPage;
template = templates.index;
data = posts.list;
};
Expand Down Expand Up @@ -115,7 +115,7 @@
pathPrefix = "/posts/";
template = templates.post.full;
# Attach the author to every blog post
author = data.author;
inherit (data) author;
};
};

Expand All @@ -131,7 +131,7 @@
*/
pageList = lib.generation.pagesToList {
inherit pages;
default = {layout = templates.layout;};
default = {inherit (templates) layout;};
};

/*
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/ghostwriter/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ with lib.lib; {
id = "ghostwriter";
name = "Ghostwriter";
license = licenses.mit;
demoPage = https://styx-static.github.io/styx-theme-ghostwriter;
homepage = https://github.com/styx-static/styx-theme-ghostwriter;
demoPage = "https://styx-static.github.io/styx-theme-ghostwriter";
homepage = "https://github.com/styx-static/styx-theme-ghostwriter";
tags = ["blog"];
documentation = readFile ./documentation.adoc;
screenshot = ./screen.png;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ with lib.lib; ''
</div>
${optionalString ((data ? menu) && (isList data.menu) && (length (data.menu) > 0)) ''
${optionalString ((data ? menu) && (isList data.menu) && (length data.menu > 0)) ''
<ul class="site-nav">
${lib.template.mapTemplate (menu: ''
<li class="site-nav-item">${templates.tag.ilink {
to = menu;
content = menu.title;
title = menu.title;
inherit (menu) title;
}}</li>
'')
data.menu}
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/hyde/example/site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
index = mkSplit {
title = "Home";
basePath = "/index";
itemsPerPage = conf.theme.itemsPerPage;
inherit (conf.theme) itemsPerPage;
template = templates.index;
data = posts.list;
};
Expand Down Expand Up @@ -139,7 +139,7 @@
# converting pages attribute set to a list
pageList = lib.generation.pagesToList {
inherit pages;
default = {layout = templates.layout;};
default = {inherit (templates) layout;};
};

site = lib.generation.mkSite {inherit files pageList;};
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/hyde/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ with lib.lib; {
id = "hyde";
name = "Hyde";
license = licenses.mit;
demoPage = https://styx-static.github.io/styx-theme-hyde;
homepage = https://github.com/styx-static/styx-theme-hyde;
demoPage = "https://styx-static.github.io/styx-theme-hyde";
homepage = "https://github.com/styx-static/styx-theme-hyde";
tags = ["blog"];
screenshot = ./screen.png;
description = ''
Expand Down
2 changes: 1 addition & 1 deletion src/data/styxthemes/hyde/templates/partials/body.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with lib.lib; let
class = lib.template.htmlAttr "class" (
(optional (conf.theme.colorScheme != null) "theme-base-${conf.theme.colorScheme}")
++ (optional (conf.theme.layout.reverse) "layout-reverse")
++ (optional conf.theme.layout.reverse "layout-reverse")
);
in ''
<body ${class}>
Expand Down
2 changes: 1 addition & 1 deletion src/data/styxthemes/nix/example/site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
# converting pages attribute set to a list
pageList = lib.generation.pagesToList {
inherit pages;
default = {layout = templates.layout;};
default = {inherit (templates) layout;};
};

site = lib.generation.mkSite {
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/nix/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ with lib.lib; {
id = "nix";
name = "Nix";
license = licenses.mit;
demoPage = https://styx-static.github.io/styx-theme-nix;
homepage = https://github.com/styx-static/styx-theme-nix;
demoPage = "https://styx-static.github.io/styx-theme-nix";
homepage = "https://github.com/styx-static/styx-theme-nix";
tags = ["minimal"];
screenshot = ./screen.png;
description = ''
Expand Down
2 changes: 1 addition & 1 deletion src/data/styxthemes/orbit/example/conf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ with lib.lib; {
summary = {
icon = "user";
title = "Career Profile";
content = (lib.data.loadFile {file = ./data/summary.md;}).content;
inherit ((lib.data.loadFile {file = ./data/summary.md;})) content;
};

/*
Expand Down
2 changes: 1 addition & 1 deletion src/data/styxthemes/orbit/example/site.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
title = "Home";
path = "/index.html";
template = templates.block-page.full;
layout = templates.layout;
inherit (templates) layout;
blocks = [
(templates.blocks.summary conf.theme.summary)
(templates.blocks.experiences conf.theme.experiences)
Expand Down
4 changes: 2 additions & 2 deletions src/data/styxthemes/orbit/meta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ with lib.lib; {
id = "orbit";
name = "Orbit";
license = licenses.cc-by-30;
demoPage = https://styx-static.github.io/styx-theme-orbit;
homepage = https://github.com/styx-static/styx-theme-orbit;
demoPage = "https://styx-static.github.io/styx-theme-orbit";
homepage = "https://github.com/styx-static/styx-theme-orbit";
tags = ["resume"];
screenshot = ./screen.png;
description = ''
Expand Down
Loading

0 comments on commit 61df29f

Please sign in to comment.