add pre-commit checks (#16)

This commit is contained in:
Johannes Kirschbauer 2023-01-25 15:54:44 +01:00 committed by GitHub
parent f756bd09d5
commit 55f0b414de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 190 additions and 58 deletions

1
.gitignore vendored
View File

@ -35,6 +35,7 @@ yarn-error.log*
# local env files
.env*.local
.pre-commit-config.yaml
# vercel
.vercel

View File

@ -1,54 +1,79 @@
# [Noogle](https://noogle.dev)
![Website](https://img.shields.io/website?down_message=noogle.dev&up_message=noogle.dev&url=https%3A%2F%2Fnoogle.dev)
![GitHub top language](https://img.shields.io/github/languages/top/hsjobeki/noogle)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/hsjobeki/noogle/main.yml)
![built-with-dream2nix](https://img.shields.io/badge/built%20with-dream2nix-blue)
# [Noogle](https://noogle.dev)
Noogle is a Nix API search engine. It allows you to search functions based on
their types and other attributes in `nix` projects. In `nixpkgs` especially
the `builtins` and `lib` attributes.
Noogle is a Nix API search engine. It allows you to search functions based on their types and other attributes in `nix` projects. In `nixpkgs` especially the `builtins` and `lib` attributes.
## Current Features
- Beginners-friendly search for nix and nix-related functions
- Expert search with directly typing type signatures
- Search functions based on:
- type
- signature
- [x] Beginners-friendly search for nix and nix-related functions
- [x] Search by **type** signatures
- [x] Sorted by relevance based on:
- id
- name
- tree-search from one type to another
## How it works
- category
- description
- example
- [ ] tree-search from one type to another
- [ ] functions from external libraries and nix frameworks
### Indexers:
## Available data
Data collections need to be up-to-date
Those collections are then combined and dumped somewhere (db / json)
Currently there are the following subsets of nix functions available.
For the indexing i currently use:
- nix/**builtins**
- nixpkgs/**lib**
- nixpkgs/build-support/**trivial-builders**
- Nixdoc (a fork) to collect nixpkgs.lib informations
- nix __dump-builtins + builtins-types.json for the nix builtins
### Search
As some parts of nix already have nixos modules their input/output can be discovered. I still lack some tool to integrate that into noogle.
- types are parsed and interpreted
- text search, looks in all metadata fields for an **exact match** word
or character sequence.
Noogle does not offer elastic search yet. And it remains open if it ever will.
### Search:
> If you have a function/set that you would like to find here,
> don't hesitate to file an issue.
- haskell-like types are parsed and splitted between input and ouput
- text search, looks in all metadata fields for an exact matching word or character sequence. I dont have elastic search yet.
# View the prototype [here](https://noogle.dev)
**View the prototype [here](https://noogle.dev)**
## We need your help / what is missing
- Parsing `Types:` into a real type signature tree
- Upstream missing type informations (like in /lib/attrsets.nix)
- Write type signatures for the `builtins` in json
- Add path, where each function can be imported from. e.g. `lib.makeOverridable` or `lib.customisation.makeOverridable` (it is available in both sets)
- Website
- improve share / social interactions
- Add filter by tags e.g. lib.lists
- Prepare for scaling up: Either use api or use indexedDB with WebAssembly for complete offline usage?
- Mobile optimization for reading on the go
- Clean up / enhance my nixdoc fork.
- Make the `sloppy` parser more error resistant
- Some valueable information can be used from the rnix AST ?
### Extend available function
Currently there is only a limited set of data.
Because nixpkgs is very inconsistently documented it is
really hard to extend the scope.
So if you want to help noogle, we must improve nixpkgs itself.
- [ ] Parsing `Types:` into a real type signature tree
- [ ] Fix: line beginnings that include Asterisk (*) : Is interpreted as List-Markdown
- [x] Upstream missing type informations (like in /lib/attrsets.nix)
- [x] Write type signatures for the `builtins` in json
- [ ] Add path, where each function can be imported from.
e.g. `lib.makeOverridable` or `lib.customisation.makeOverridable`
it is available in both sets
### Website
- [x] improve share (deeplinks)
- [ ] social interactions
- [ ] Add filter by tags e.g. lib.lists
- [ ] Prepare for scaling up (we expect more users)
- [x] Mobile optimization for reading on the go
## Nixdoc / Indexer (fork)
- [ ] Parse types directly while also parsing comments
- [ ] Extend the scope, so that is can parse more comments
## Contribute
@ -62,4 +87,5 @@ Contributions are very welcome just file a PR or issue
`nix develop`
This command creates the node_modules folder with all needed dependencies based on dream2nix.
This command creates the node_modules folder
with all needed dependencies based on dream2nix.

View File

@ -1,5 +1,4 @@
import {
Box,
IconButton,
ListItemText,
Paper,
@ -9,15 +8,10 @@ import {
Typography,
} from "@mui/material";
import { useMemo } from "react";
import { DocItem, NixType } from "../../models/nix";
import { DocItem } from "../../models/nix";
import { Preview } from "../preview/preview";
import StarIcon from "@mui/icons-material/Star";
import ShareIcon from "@mui/icons-material/Share";
import { useLocalStorage } from "usehooks-ts";
import { useSnackbar } from "notistack";
import StarRateIcon from "@mui/icons-material/StarRate";
import StarBorderIcon from "@mui/icons-material/StarBorder";
import { Key } from "@mui/icons-material";
interface FunctionItemProps {
selected: boolean;
@ -25,10 +19,9 @@ interface FunctionItemProps {
docItem: DocItem;
handleClose: () => void;
}
const getKey = (item: DocItem) => `${item.category}/${item.name}`;
export default function FunctionItem(props: FunctionItemProps) {
const { name, docItem, selected, handleClose } = props;
const { docItem, selected, handleClose } = props;
const { fn_type, category, description, id } = docItem;
const { enqueueSnackbar } = useSnackbar();
const descriptionPreview = useMemo(() => {

View File

@ -3,12 +3,11 @@ import Paper from "@mui/material/Paper";
import InputBase from "@mui/material/InputBase";
import IconButton from "@mui/material/IconButton";
import ClearIcon from "@mui/icons-material/Clear";
import { Box, debounce, Grid, Tooltip, Typography } from "@mui/material";
import { Box, debounce, Grid, Typography } from "@mui/material";
import ChevronRightIcon from "@mui/icons-material/ChevronRight";
import { NixType, nixTypes } from "../../models/nix";
import SearchIcon from "@mui/icons-material/Search";
import { usePageContext } from "../pageContext";
import { initialPageState } from "../../models/internals";
import { SelectOption } from "../selectOption";
export type Filter = { from: NixType; to: NixType };

View File

@ -125,6 +125,22 @@
"type": "github"
}
},
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"type": "github"
},
"original": {
"owner": "edolstra",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
@ -173,6 +189,21 @@
"type": "github"
}
},
"flake-utils_2": {
"locked": {
"lastModified": 1667395993,
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"flakeCompat": {
"flake": false,
"locked": {
@ -205,6 +236,27 @@
"url": "https://gitlab.haskell.org/bgamari/ghc-utils"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1660459072,
"narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "a20de23b925fd8264fd7fad6454652e142fd7f73",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"gomod2nix": {
"flake": false,
"locked": {
@ -309,6 +361,22 @@
"type": "github"
}
},
"nixpkgs-stable": {
"locked": {
"lastModified": 1673800717,
"narHash": "sha256-SFHraUqLSu5cC6IxTprex/nTsI81ZQAtDvlBvGDWfnA=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2f9fd351ec37f5d479556cd48be4ca340da59b8f",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-22.11",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1673027386,
@ -395,11 +463,36 @@
"type": "github"
}
},
"pre-commit-hooks_2": {
"inputs": {
"flake-compat": "flake-compat",
"flake-utils": "flake-utils_2",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": "nixpkgs-stable"
},
"locked": {
"lastModified": 1674550893,
"narHash": "sha256-HXI8AB96PP7UZ7iPANACXM8qc9eMz0ljxBEDM8JJKhY=",
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"rev": "7bdf85f6bbef581eb687838d19f2b35a4c9d77f0",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "pre-commit-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"dream2nix": "dream2nix",
"nixdoc-fork": "nixdoc-fork",
"nixpkgs": "nixpkgs_4"
"nixpkgs": "nixpkgs_4",
"pre-commit-hooks": "pre-commit-hooks_2"
}
},
"rust-analyzer-src": {

View File

@ -1,12 +1,18 @@
{
inputs.dream2nix.url = "github:nix-community/dream2nix";
inputs.nixdoc-fork.url = "github:hsjobeki/nixdoc";
outputs = {self, nixpkgs,...}@inp:
let
system = "x86_64-linux";
pkgs = inp.nixpkgs.legacyPackages.${system};
inherit (builtins.fromJSON (builtins.readFile ./package.json)) name;
in
inputs = {
dream2nix.url = "github:nix-community/dream2nix";
nixdoc-fork.url = "github:hsjobeki/nixdoc";
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, pre-commit-hooks, ... }@inp:
let
system = "x86_64-linux";
pkgs = inp.nixpkgs.legacyPackages.${system};
inherit (builtins.fromJSON (builtins.readFile ./package.json)) name;
in
(inp.dream2nix.lib.makeFlakeOutputs {
systemsFromFile = ./nix_systems;
config.projectRoot = ./.;
@ -19,7 +25,7 @@
packageOverrides = {
${name}.staticPage = {
preBuild = ''
cp ${inp.nixdoc-fork.packages.${system}.data} ./models/lib.json
cp ${inp.nixdoc-fork.packages.${system}.data} ./models/lib.json
'';
installPhase = ''
runHook preInstall
@ -35,7 +41,20 @@
})
// {
devShells.${system}.default = pkgs.mkShell {
buildInputs = with pkgs; [nodejs-18_x ];
buildInputs = with pkgs; [ nodejs-18_x ];
shellHook = ''
${self.checks.${system}.pre-commit-check.shellHook}
'';
};
checks.${system} = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
nixpkgs-fmt.enable = true;
statix.enable = true;
markdownlint.enable = true;
};
};
};
};

View File

@ -3,6 +3,7 @@
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"noUnusedLocals": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
@ -16,5 +17,5 @@
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
"exclude": ["node_modules", "result"]
}