npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-filenames-suffix

v1.2.3

Published

Eslint rule for consistent filenames.

Downloads

159

Readme

eslint-plugin-filenames-suffix

Adds eslint rules to ensure consistent filenames for your javascript files.

Please note: This plugin will only lint the filenames of the .js, .jsx files you are linting with eslint. It will ignore other files that are not linted with eslint.

Enabling the plugin

This plugin requires a version of eslint>=1.0.0 to be installed as a peer dependency.

Modify your .eslintrc file to load the plugin and enable the rules you want to use.

{
  "plugins": [
    "filenames-suffix"
  ],
  "rules": {
    "filenames-suffix/match-regex": 2,
    "filenames-suffix/match-exported": 2,
    "filenames-suffix/no-index": 2
  }
}

Rules

Consistent Filenames via regex (match-regex)

A rule to enforce a certain file naming convention using a regular expression.

The convention can be configured using a regular expression (the default is camelCase.js). Additionally exporting files can be ignored with a second configuration parameter.

"filenames-suffix/match-regex": [2, "^[a-z_]+$", true]

With these configuration options, camelCase.js will be reported as an error while snake_case.js will pass. Additionally the files that have a named default export (according to the logic in the match-exported rule) will be ignored. They could be linted with the match-exported rule.

Matching Exported Values (match-exported)

Match the file name against the default exported value in the module. Files that dont have a default export will be ignored. The exports of index.js are matched against their parent directory.

// Considered problem only if the file isn't named foo.js or foo/index.js
export default function foo() {}

// Considered problem only if the file isn't named Foo.js or Foo/index.js
module.exports = class Foo() {}

// Considered problem only if the file isn't named someVariable.js or someVariable/index.js
module.exports = someVariable;

// Never considered a problem
export default { foo: "bar" };

If your filename policy doesn't quite match with your variable naming policy, you can add a tansform:

"filenames-suffix/match-exported": [2, "kebab"]

Now, in your code:

// Considered problem only if file isn't named variable-name.js or variable-name/index.js
export default function variableName;

Available transforms: 'snake', 'kebab', and 'camel'

In addition to applying a transform, you can also allow files to have suffixes. A suffix describes the type of module the file exports. A suffix is a singular word that is separated from the filename by a . and precedes the file extension, e.g. filename.suffix.ext. A file with a suffix must reside in a directory whose name is the plural version of the suffix, or a subdirectory therein. So for example, if suffixes are enabled and a file is named example.component.jsx, it must live in a directory named components or a subdirectory of it.

"filenames-suffix/match-exported": [2, "kebab", "check-suffix"]

index files do not require a suffix.

Don't allow index.js files (no-index)

Having a bunch of index.js files can have negative influence on developer experience, e.g. when opening files by name. When enabling this rule. index.js files will always be considered a problem.

Changelog

1.1.0

  • Introduce transform option for match-exported

1.0.0

  • Split rule into match-regex, match-exported and no-index

0.2.0

  • Add match-exported flags

0.1.2

  • Fix example in README

0.1.1

  • Fix: Text via stdin always passes
  • Tests: Travis builds also run on node 0.12 and iojs now

0.1.0

  • Initial Release