mlflow--mlflow
Custom ESLint Rules
This directory contains custom ESLint rules specific to the MLflow OSS UI codebase.
How It Works
This package is a yarn workspace referenced by mlflow/server/js/package.json as @mlflow/eslint-plugin.
In mlflow/server/js/.eslintrc.js, we automatically load the recommended rules in index.js.
Adding New Custom Rules
- Create a new
.jsfile in this directory (e.g.,my-custom-rule.js) - Export an ESLint rule module with
metaandcreatefunctions:
module.exports = {
meta: {
type: 'problem',
docs: {
description: 'Description of your rule',
category: 'Best Practices',
recommended: true,
},
messages: {
myMessage: 'Your error message here',
},
},
create(context) {
return {
// Your rule implementation
};
},
};
- Import the rule in
index.js, and add it to therulessections of the export (add to the top-levelrulesconfig as well as the one inrecommended):
const myCustomRule = require('./my-custom-rule');
module.exports = {
rules: {
// ...
'my-custom-rule': myCustomRule,
},
configs: {
recommended: {
plugins: ['@mlflow'],
rules: {
'@mlflow/my-custom-rule': 'error',
},
},
},
};
-
Run
yarn installfrommlflow/server/jsto make sure the new rules are loaded -
Run
yarn lintfrommlflow/server/jsto make sure the new rule works as intended
Testing Custom Rules
Run yarn test to run all tests in the directory. We currently use ESlint's RuleTester util to
write unit tests for our rules. Alternatively you can spot-check by running yarn lint in
mlflow/server/js on files you expect to fail your rule.