sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.15k stars 249 forks source link

Issue: not-to-spec and not-to-dev-dep default config should include tsx and jsx #916

Closed jg210 closed 6 months ago

jg210 commented 6 months ago

Include jsx and tsx extensions, for React JSX support.

Expected Behavior

    {
      name: 'not-to-spec',
      comment:
        'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' +
        "If there's something in a spec that's of use to other modules, it doesn't have that single " +
        'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',
      severity: 'error',
      from: {},
      to: {
        path: '[.](spec|test)[.](js|jsx|mjs|cjs|ts|tsx|ls|coffee|litcoffee|coffee[.]md)$'
      }
    },
    {
      name: 'not-to-dev-dep',
      severity: 'error',
      comment:
        "This module depends on an npm package from the 'devDependencies' section of your " +
        'package.json. It looks like something that ships to production, though. To prevent problems ' +
        "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" +
        'section of your package.json. If this module is development only - add it to the ' +
        'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
      from: {
        path: '^(src)',
        pathNot: '[.](spec|test)[.](js|jsx|mjs|cjs|ts|tsx|ls|coffee|litcoffee|coffee[.]md)$'
      },

Current Behavior

    {
      name: 'not-to-spec',
      comment:
        'This module depends on a spec (test) file. The sole responsibility of a spec file is to test code. ' +
        "If there's something in a spec that's of use to other modules, it doesn't have that single " +
        'responsibility anymore. Factor it out into (e.g.) a separate utility/ helper or a mock.',
      severity: 'error',
      from: {},
      to: {
        path: '[.](spec|test)[.](js|mjs|cjs|ts|ls|coffee|litcoffee|coffee[.]md)$'
      }
    },
    {
      name: 'not-to-dev-dep',
      severity: 'error',
      comment:
        "This module depends on an npm package from the 'devDependencies' section of your " +
        'package.json. It looks like something that ships to production, though. To prevent problems ' +
        "with npm packages that aren't there on production declare it (only!) in the 'dependencies'" +
        'section of your package.json. If this module is development only - add it to the ' +
        'from.pathNot re of the not-to-dev-dep rule in the dependency-cruiser configuration',
      from: {
        path: '^(src)',
        pathNot: '[.](spec|test)[.](js|mjs|cjs|ts|ls|coffee|litcoffee|coffee[.]md)$'
      },

Possible Solution

Steps to Reproduce (for bugs)

npx depcruise --init

Context

I got spurious errors from this, e.g.:

 error not-to-dev-dep: src/__tests__/TableRow.test.tsx → node_modules/@testing-library/react/dist/@testing-library/react.esm.js

Your Environment

sverweij commented 6 months ago

Hi @jg210 thanks for raising this - and these extensions should for sure be in that default list. I'll update the init template to include them (together with .cts and .mts).

sverweij commented 6 months ago

Hi @jg210 as you can see above the fix is in the main branch, ready to be released - future users of the --init command won't bump into the same issue did, so thanks on behalf of them as well!

There's a few small chores I want to go with the upcoming release as well - it'll be on npmjs within the coming days.

sverweij commented 6 months ago

☝️ @jg210 the version with the fix is being published to npmjs right now, so when you read this you should be able to use it.

Thanks again!