Code Monkey home page Code Monkey logo

Comments (10)

webpro avatar webpro commented on September 23, 2024

Thanks @weilbith!

I didn't know about .git/info/exclude, that looks useful indeed.

For now, you could consider using a dynamic knip.ts, read .git/info/exclude, and its items to knip ignore patterns (or as negated entry/project patterns).

from knip.

weilbith avatar weilbith commented on September 23, 2024

Wow, that was a fast reply! 😱
Thank you very much!

Ah, cool. That actually sounds like a sound idea!
I'll implement that for now. Do you think it will make it as a feature upstream? Should I contribute a PR?


In case someone stumbles across this issue and it is not (yet) implemented upstream, here is my version of adding it to my knip.ts configuration:

import { readFile } from "fs/promises";
import type { KnipConfig } from "knip";

// TODO: Remove once feature was implemented upstream.
async function readGitInfoExcludePatterns(): Promise<string[]> {
  const buffer = await readFile(".git/info/exclude");
  return buffer
    .toString("utf-8")
    .split(/\r\n|\r|\n/)
    .filter((line) => !!line.trim())
    .filter((line) => !line.startsWith("#"))
    .map((line) => (line.endsWith("/") ? `${line}**` : line));
}

export default async function composeConfiguration(): Promise<KnipConfig> {
  const gitInfoExcludePatterns = await readGitInfoExcludePatterns();

  return {
    ignore: [
      ...gitInfoExcludePatterns,
      // ... more patterns
    ],
    // ... more configuration
  };
}

from knip.

webpro avatar webpro commented on September 23, 2024

Thanks for sharing your solution!

Feel free to give this a shot. That part of the code is here: https://github.com/webpro/knip/blob/main/packages/knip/src/util/globby.ts#L59

from knip.

weilbith avatar weilbith commented on September 23, 2024

Feel free to give this a shot. That part of the code is here: https://github.com/webpro/knip/blob/main/packages/knip/src/util/globby.ts#L59

Hui, that's a function 😄
Let me see. Thinking about how to integrate it best. Because the current logic seem to be quite evolved, acting on various levels including the search for .gitignore files, while there is always only a single .git/info/exclude. 🤔

from knip.

webpro avatar webpro commented on September 23, 2024

Maybe you could consider something like moving everything inside the if clause of entryFilter to a separate function and call that function once for .git/info/exclude.

from knip.

webpro avatar webpro commented on September 23, 2024

@weilbith Is this still something you fancy picking up? I have absolutely no hurries with this one, just checking up.

from knip.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.