Giter VIP home page Giter VIP logo

Comments (10)

fsmaia avatar fsmaia commented on June 19, 2024 4

I would love to contribute to it too. I have developed a rule enforcing a custom file structure, but it could be easily adjusted.

from eslint-plugin-filenames.

AndersDJohnson avatar AndersDJohnson commented on June 19, 2024

@selaux @markalfred I would love this feature as well. For backwards compatibility, maybe enable as an option to filenames/match-regex to match full file paths instead of just base file names?

Not sure if we should try to trim the absolute paths to be relative to the project root - may be tricky.

Would you accept a pull request and consider a release, or is it not worth my time?

from eslint-plugin-filenames.

selaux avatar selaux commented on June 19, 2024

@AndersDJohnson Sure, I would gladly accept a PR. match-regex could be extended to match each path segment relative to root. Not sure how to find the root though 😉

from eslint-plugin-filenames.

vhlongon avatar vhlongon commented on June 19, 2024

Hi @selaux I am working on this but I am not sure how to set the root folder in my tests. I have a failing test now that should pass:

{
            code: testCode,
            filename: "SomeDir/VariableName.js",
            // parserOptions: { ecmaVersion: 6, sourceType: "module" },
            options: ['pascal']
        },

The Dirname returned is foo/SomeDir where it should be Foo/SomeDir, but I am not sure how to set foo to Foo

from eslint-plugin-filenames.

vhlongon avatar vhlongon commented on June 19, 2024

How can I change which root folder is sent? It should differ to match-dirname tests, since I don't want /fooas in the other tests.

from eslint-plugin-filenames.

selaux avatar selaux commented on June 19, 2024

Can you upload the code, so I can have a look at it? I don't fully understand the question yet...

from eslint-plugin-filenames.

Xooone47 avatar Xooone47 commented on June 19, 2024

I would love to contribute to it too. I have developed a rule enforcing a custom file structure, but it could be easily adjusted.

what about your rules now?

from eslint-plugin-filenames.

fsmaia avatar fsmaia commented on June 19, 2024

As it is small, I will post its entire code here.

Keep in mind that is was developed for an opinionated file structure (feature-based with layers inside of the features).

module.exports = {
  meta: {
    docs: {
      description: 'This rule enforces a file path to match the guideline',
      recommended: true,
    },
    messages: {
      [MATCH_PATH_MESSAGE]: "File path '{{ pathDir }}' should match the guideline",
    },
  },

  create: (context) => {
    //----------------------------------------------------------------------
    // Public
    //----------------------------------------------------------------------
    const joinOptions = (options) => `(${options.join('|')})`;

    return {
      Program: (node) => {
        const filename = path.resolve(context.getFilename()).replace(/\\/g, '/');
        const rootFile = joinOptions(['serviceWorker', 'store']);

        const validFiles = [
          `${SRC_FOLDER}/${rootFile}.(js|ts)`, // src root files
          `${SRC_FOLDER}/index((.integration)?.test)?.(js|ts|tsx)`, // src root file
          `${SRC_FOLDER}/router.(js|tsx)`, // root router file
          `${SRC_FOLDER}/modules/index.(js|ts)`, // modules entrypoint
          `${SRC_FOLDER}/${I18N_LAYER_FOLDER}/${I18N_CASE}.json`,
          `${FEATURE_FOLDER}(/${LAYER_FOLDER})?/index((.integration)?.test)?.(js|ts)`, // entrypoints
          `${FEATURE_FOLDER}/${NAMESPACED_LAYER_FOLDER}(/${KEBAB_CASE})?/index(.test)?.(js|ts)`,
          `${FEATURE_FOLDER}/${LAYERS.DECORATORS}(/${KEBAB_CASE})?/index(.test)?.tsx`, // decorators may have JSX
          `${FEATURE_FOLDER}/${CONSTANTS_LAYER_FOLDER}/${KEBAB_CASE}.(js|ts)`,
          `${FEATURE_FOLDER}/${REACT_LAYER_FOLDER}(/${PASCAL_CASE})?/index.scss`,
          `${FEATURE_FOLDER}/${REACT_LAYER_FOLDER}(/${PASCAL_CASE})?/index((.integration)?.test|.story)?.(js|tsx)`,
          `${FEATURE_FOLDER}/${TYPESCRIPT_LAYER_FOLDER}/${PASCAL_CASE}.ts`,
          `${FEATURE_FOLDER}/${FREESTYLE_LAYER_FOLDER}.*`,
        ];

        const validFilesRegExp = new RegExp(`${joinOptions(validFiles)}$`);
        const fileIndex = filename.indexOf('src');

        if (filename.match('src') && !filename.match(validFilesRegExp)) {
          context.report({
            node,
            messageId: MATCH_PATH_MESSAGE,
            data: { pathDir: filename.slice(fileIndex) },
          });
        }
      },
    };
  },
};

from eslint-plugin-filenames.

YuriiBoikoOpn avatar YuriiBoikoOpn commented on June 19, 2024

also will be great to have similar rule for folders, as you have for files: filename-case

from eslint-plugin-filenames.

Igorkowalski94 avatar Igorkowalski94 commented on June 19, 2024

As an alternative, you can use eslint-plugin-project-structure

features:
✅ Validation of project structure (Any files/folders outside the structure will be considered an error).
✅ Validation of folder and file names.
✅ Name case validation.
✅ Name regex validation.
✅ File extension validation (Support for all extensions).
✅ Inheriting the parent's name (The child inherits the name of the folder in which it is located).
✅ Folder recursion (You can nest a given folder structure recursively).
✅ Forcing a nested/flat structure for a given folder.

from eslint-plugin-filenames.

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.